Files
NativeScript/apps/tests/file-system.md
Erjan Gavalji f15f283c74 Reorder test file structure to match the modules
Needed to have a nice structured cookbook dir in the docs

Includes:
Move the data-module tests under the data dir
Move the frame tests under the ui dir
Rename the dialog.md file to dialogs.md
Fix the web-view title
Add previous_url attributes to each article for SEO
Rename the style dir to styling to match the reference
Fix the frame-tests path
2016-05-05 10:43:35 +03:00

2.6 KiB

nav-title, title, description, previous_url
nav-title title description previous_url
file-system How-To file-system Examples for using file-system /ApiReference/file-system/HOW-TO

File System

Using the file system requires the FileSystem module. The pre-required fs module is used throughout the following code snippets.

Path

Normalize a Path

Path Join

Concatenate a path to a file by providing multiple path arguments.

Get the Path Separator

Get or Create a File With Path

The following example writes some text to a file created for path. It will create a new file or overwrite an existing file.

Get or Create a Folder With Path

Create

Writing a string to a File

The following example writes some text to a file. It will create a new file or overwrite an existing file.

Get or Create a File

Get or Create a Folder

Read

Reading from a File

The following example writes some text to a file and then reads it back.

Reading/writing binary data from/to a File

Getting the Known Folders

Each app has several well known folders. This is how to access them:

Getting Folder Contents

Getting all files and folders within a folder:

Enumerating Folder Contents

Getting all folder entities in array may be slow with large number of files. Enumerating the folder entities would iterate the files one by one without blocking the UI.

Getting Parent Folder

Getting File Name and Extension

Checking if a File Exists

Checking if a Folder Exists

Update

Renaming a File

Renaming a Folder

Delete

Removing a File

To 'delete', 'remove' or 'unlink' a file use the file's remove method:

Removing a Folder

Clearing the Contents of a Folder

The clear method removes all files within a folder.