Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/ng-framework-modules-category/connectivity/end.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
| Name | Type |
|----------|---------|
| [tns-core-modules/connectivity](https://docs.nativescript.org/api-reference/modules/_connectivity_.html) | `Module` |
| [connectionTypoe](https://docs.nativescript.org/api-reference/enums/_connectivity_.connectiontype) | `Enum` |
| [connectionType](https://docs.nativescript.org/api-reference/enums/_connectivity_.connectiontype) | `Enum` |

## Native Component

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// >> connectivity-start-code
import { Component, OnInit, OnDestroy } from "@angular/core";
import {
getConnectionType,
startMonitoring,
stopMonitoring
import {
getConnectionType,
startMonitoring,
stopMonitoring
} from "tns-core-modules/connectivity";
import * as connectivityModule from "tns-core-modules/connectivity";

Expand Down Expand Up @@ -66,4 +66,4 @@ export class UsageComponent implements OnInit, OnDestroy {
stopMonitoring();
}
}
// << connectivity-start-code
// << connectivity-start-code

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Component } from "@angular/core";
// >> fs-delete-import-code
import * as fs from "tns-core-modules/file-system";
import { File, Folder, knownFolders } from "tns-core-modules/file-system";
// << fs-delete-import-code
@Component({
moduleId: module.id,
templateUrl: "./delete.component.html"
})
export class DeleteExampleComponent {

public documents: fs.Folder;
public file: fs.File;
public myFolder: fs.Folder;
public documents: Folder;
public file: File;
public myFolder: Folder;

public resultMessage: string = "";

constructor() {
this.documents = fs.knownFolders.documents();
this.documents = knownFolders.documents();
this.myFolder = this.documents.getFolder("TestFolderName");
this.file = this.myFolder.getFile("TestFileName.txt");
}
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DeleteExampleComponent {
}

public onReset() {
this.documents = fs.knownFolders.documents();
this.documents = knownFolders.documents();
this.myFolder = this.documents.getFolder("TestFolderName");
this.file = this.myFolder.getFile("TestFileName.txt");
this.resultMessage = "Successfully reset!";
Expand Down
86 changes: 82 additions & 4 deletions app/ng-framework-modules-category/file-system/end.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
## File Properties

| Name | Type | Description |
|----------|---------|----------------|
| `extension` | `string` | Gets the extension of the file. |
| `isLocked` | `boolean` | Gets a value indicating whether the file is currently locked, meaning a background operation associated with this file is running. |
| `lastModified` | `Date` | Gets the Date object specifying the last time this entity was modified. |
| `name` | `string` | Gets the name of the entity. |
| `parent` | `Folder` | Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary. This property is readonly. |
| `path` | `string` | Gets the fully-qualified path (including the extension for a File) of the entity.|
| `size` | `number` | Gets the size in bytes of the file. |

## File Methods

| Name | Return Type | Description |
|----------|---------|----------------|
| `read` | `Promise<any>` | Reads the binary content of the file asynchronously. |
| `readSync(onError?: function)` | `any` | Reads the binary content of the file synchronously. |
| `readText(encoding?: string)` | `Promise<string>` | Reads the content of the file as a string using the specified encoding (defaults to UTF-8). |
| `readTextSync(onError?: function, encoding?: string)` | `string` | Reads the content of the file as a string synchronously, using the specified encoding (defaults to UTF-8). |
| `remove` | `void` | Removes (deletes) the current Entity from the file system. |
| `removeSync(onError?: function)` | `void` | Removes (deletes) the current Entity from the file system synchronously.|
| `rename(newName: string)` | `Promise<any>` | Renames the current entity using the specified name. |
| `renameSync(newName: string, onError?: function)` | `void` | Renames the current entity synchronously, using the specified name. |
| `write(newName: string)` | `Promise<void>` | Writes the provided binary content to the file. |
| `writeSync(newName: string, onError?: function)` | `void` | Writes the provided binary content to the file synchronously. |
| `writeText(encoding?: string)` | `Promise<string>` | Writes the content of the file as a string using the specified encoding (defaults to UTF-8). |
| `writeTextSync(onError?: function, encoding?: string)` | `string` | Writes the content of the file as a string synchronously, using the specified encoding (defaults to UTF-8). |
| `exists(path: string)` | `boolean` | Checks whether a File with the specified path already exists. |
| `fromPath(path: string)` | `File` | Gets or creates a File entity at the specified path. |

## Folder Properties

| Name | Type | Description |
|----------|---------|----------------|
| `isKnown` | `boolean` | Determines whether this instance is a KnownFolder (accessed through the KnownFolders object). |
| `lastModified` | `Date` | Gets the Date object specifying the last time this entity was modified. |
| `name` | `string` | Gets the name of the entity. |
| `parent` | `Folder` | Gets the Folder object representing the parent of this entity. Will be null for a root folder like Documents or Temporary. This property is readonly. |
| `path` | `string` | Gets the fully-qualified path (including the extension for a File) of the entity.|

## Folder Methods

| Name | Return Type | Description |
|----------|---------|----------------|
| `clear` | `Promise<any>` | Deletes all the files and folders (recursively), contained within this Folder. |
| `clearSync(onError?: function)` | `void` | Deletes all the files and folders (recursively), contained within this Folder synchronously. |
| `contains(name: string)` | `boolean` | Checks whether this Folder contains an Entity with the specified name. The path of the folder is added to the name to resolve the complete path to check for. |
| `eachEntity(onEntity: function)` | `any` | Enumerates all the top-level FileSystem entities residing within this folder. |
| `getEntities` | `Promise<Array<FileSystemEntity>>` | Gets all the top-level entities residing within this folder. |
| `getEntitiesSync(onError?: function)` | `Array<FileSystemEntity>` | Gets all the top-level entities residing within this folder synchronously |
| `getFile(name: string)` | `File` | Gets or creates a File entity with the specified name within this Folder. |
| `getFolder(name: string)` | `Folder` | Gets or creates a Folder entity with the specified name within this Folder. |
| `remove` | `Promise<any>` | Removes (deletes) the current Entity from the file system. |
| `removeSync` | `removeSync(onError?: function)` | Removes (deletes) the current Entity from the file system synchronously. |

## knownFolders Methods

| Name | Return Type | Description |
|----------|---------|----------------|
| `currentApp` | `Folder` | Gets the root folder for the current application. This Folder is private for the application and not accessible from Users/External apps. iOS - this folder is read-only and contains the app and all its resources. |
| `documents` | `Folder` | Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps. |
| `temp` | `Folder` | Gets the Temporary (Caches) folder available for the current application. This Folder is private for the application and not accessible from Users/External apps. |

## path Methods

| Name | Return Type | Description |
|----------|---------|----------------|
| `join(...paths: string[])` | `string` | Joins all the provided string components, forming a valid and normalized path. |
| `normalize(path: string)` | `string` | Normalizes a path, taking care of occurrances like ".." and "//". |


## API References

| Name | Type |
|----------|---------|
| [tns-core-modules/file-system](https://docs.nativescript.org/api-reference/modules/_file_system_.html) | `Module` |
| [FileSystem](https://docs.nativescript.org/api-reference/classes/_file_system_.file.html) | `Class` |
| [FileSystemEntity](https://docs.nativescript.org/api-reference/classes/_file_system_.filesystementity.html) | `Class` |
| [Folder](https://docs.nativescript.org/api-reference/classes/_file_system_.folder.html) | `Class` |
| [knownFolders](https://docs.nativescript.org/api-reference/modules/_file_system_.knownfolders) | `Module` |
| [path](https://docs.nativescript.org/api-reference/modules/_file_system_.path) | `Module` |

**API Reference for the** [File System Module](https://docs.nativescript.org/api-reference/modules/_file_system_.html)
**API Reference for the** [File Class](https://docs.nativescript.org/api-reference/classes/_file_system_.file.html)
**API Reference for the** [FileSystemEntity Class](https://docs.nativescript.org/api-reference/classes/_file_system_.filesystementity.html)
**API Reference for the** [Folder Class](https://docs.nativescript.org/api-reference/classes/_file_system_.folder.html)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link } from "./../../link";

let menuLinks = [
new Link("Paths", "/file-system/paths"),
new Link("Create", "/file-system/create"),
new Link("Create", "/file-system/usage"),
new Link("Read", "/file-system/read"),
new Link("Update", "/file-system/update"),
new Link("Delete", "/file-system/delete")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { FileSystemExamplesComponent } from "./file-system-examples.component";
import { CreateExampleComponent } from "./create/create.component";
import { CreateExampleComponent } from "./usage/usage.component";
import { DeleteExampleComponent } from "./delete/delete.component";
import { PathsExampleComponent } from "./paths/paths.component";
import { ReadExampleComponent } from "./read/read.component";
Expand All @@ -15,9 +15,9 @@ export const routerConfig = [
component: FileSystemExamplesComponent
},
{
path: "create",
path: "usage",
component: CreateExampleComponent,
data: { title: "Create" }
data: { title: "Usage" }
},
{
path: "delete",
Expand Down
2 changes: 1 addition & 1 deletion app/ng-framework-modules-category/file-system/overview.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File System module provides high-level abstractions for file system entities
The File System module provides high-level abstractions for file system entities
such as files, folders, known folders, paths, separators, etc.
17 changes: 0 additions & 17 deletions app/ng-framework-modules-category/file-system/paths/article.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit } from "@angular/core";
// >> fs-paths-import-code
import * as fs from "tns-core-modules/file-system";
import { knownFolders, path, File, Folder } from "tns-core-modules/file-system";
// << fs-paths-import-code

@Component({
Expand All @@ -18,42 +18,42 @@ export class PathsExampleComponent implements OnInit {

ngOnInit() {
// >> fs-paths-normalize-code
let documentsFolder = fs.knownFolders.documents();
let currentAppFolder = fs.knownFolders.currentApp();
let tempFolder = fs.knownFolders.temp();
let documentsFolder = knownFolders.documents();
let currentAppFolder = knownFolders.currentApp();
let tempFolder = knownFolders.temp();

let testPath = "///test.txt";
// Get a normalized path such as <folder.path>/test.txt from <folder.path>///test.txt
this.documents = fs.path.normalize(documentsFolder.path + testPath);
this.currentApp = fs.path.normalize(currentAppFolder.path + testPath);
this.temp = fs.path.normalize(tempFolder.path + testPath);
this.documents = path.normalize(documentsFolder.path + testPath);
this.currentApp = path.normalize(currentAppFolder.path + testPath);
this.temp = path.normalize(tempFolder.path + testPath);
// << fs-paths-normalize-code

// >> fs-paths-join-code
// Generate a path like <documents.path>/myFiles/test.txt
documentsFolder = fs.knownFolders.documents();
let filePath = fs.path.join(documentsFolder.path, "myFiles", "test.txt");
documentsFolder = knownFolders.documents();
let filePath = path.join(documentsFolder.path, "myFiles", "test.txt");
// << fs-paths-join-code
console.log(filePath);

// >> fs-paths-separator-code
// An OS dependent path separator, "\" or "/".
let separator = fs.path.separator;
let separator = path.separator;
// << fs-paths-separator-code
console.log(separator);

// >> fs-paths-create-folder-code
let folderPath = fs.path.join(fs.knownFolders.documents().path, "music");
let folder = fs.Folder.fromPath(folderPath);
let folderPath = path.join(knownFolders.documents().path, "music");
let folder = Folder.fromPath(folderPath);
// << fs-paths-create-folder-code
console.log(folder);
}

public onSaveContentToFile() {
// >> fs-paths-create-file-code
let documentsFolder = fs.knownFolders.documents();
let path = fs.path.join(documentsFolder.path, "FileFromPath.txt");
let file = fs.File.fromPath(path);
let documentsFolder = knownFolders.documents();
let myPath = path.join(documentsFolder.path, "FileFromPath.txt");
let file = File.fromPath(myPath);

// Writing text to the file.
file.writeText(this.textContentToBeSaved)
Expand Down
23 changes: 0 additions & 23 deletions app/ng-framework-modules-category/file-system/read/article.md

This file was deleted.

Loading