File

Improve this doc

$ ionic plugin add cordova-plugin-file

Repo: https://github.com/apache/cordova-plugin-file

This plugin implements a File API allowing read/write access to files residing on the device.

This plugin is based on several specs, including : The HTML5 File API http://www.w3.org/TR/FileAPI/ The (now-defunct) Directories and System extensions Latest: http://www.w3.org/TR/2012/WD-file-system-api-20120417/ Although most of the plugin code was written when an earlier spec was current: http://www.w3.org/TR/2011/WD-file-system-api-20110419/ It also implements the FileWriter spec : http://dev.w3.org/2009/dap/file-system/file-writer.html

Static Methods

cordovaFileError()

checkDir(path, dir)

Check if a directory exists in a certain path, directory.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

dir string

Name of directory to check

Returns: Returns a Promise that resolves or rejects with an error.

createDir(path, dirName, replace)

Creates a new directory in the specific path. The replace boolean value determines whether to replace an existing directory with the same name. If an existing directory exists and the replace value is false, the promise will fail and return an error.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

dirName string

Name of directory to create

replace boolean

If true, replaces file with same name. If false returns error

Returns: Returns a Promise that resolves or rejects with an error.

removeDir(path, dirName)

Remove a directory at a given path

Param Type Details
path string

The path to the directory

dirName string

The directory name

Returns: Returns a Promise that resolves or rejects with an error.

moveDir(path, dirName, newPath, newDirName)

Move a directory to a given path

Param Type Details
path string

The source path to the directory

dirName string

The source directory name

newPath string

The destionation path to the directory

newDirName string

The destination directory name

Returns: Returns a Promise that resolves or rejects with an error.

copyDir(path, dirName, newPath, newDirName)

Copy a directory in various methods. If destination directory exists, will fail to copy.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

dirName string

Name of directory to copy

newPath string

Base FileSystem of new location

newDirName string

New name of directory to copy to (leave blank to remain the same)

Returns: Returns a Promise that resolves or rejects with an error.

listDir(path, dirName)

List files and directory from a given path

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

dirName string

Name of directory

Returns: Returns a Promise that resolves or rejects with an error.

removeRecursively(path, dirName)

Removes all files and the directory from a desired location.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

dirName string

Name of directory

Returns: Returns a Promise that resolves or rejects with an error.

checkFile(path, file)

Check if a file exists in a certain path, directory.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

file string

Name of file to check

Returns: Returns a Promise that resolves or rejects with an error.

createFile(path, fileName, replace)

Creates a new file in the specific path. The replace boolean value determines whether to replace an existing file with the same name. If an existing file exists and the replace value is false, the promise will fail and return an error.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

fileName string

Name of file to create

replace boolean

If true, replaces file with same name. If false returns error

Returns: Returns a Promise that resolves or rejects with an error.

removeFile(path, fileName)

Removes a file from a desired location.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

fileName string

Name of file to remove

Returns: Returns a Promise that resolves or rejects with an error.

moveFile(path, fileName, newPath, newFileName)

Move a file to a given path.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

fileName string

Name of file to move

newPath string

Base FileSystem of new location

newFileName string

New name of file to move to (leave blank to remain the same)

Returns: Returns a Promise that resolves or rejects with an error.

copyFile(path, fileName, newPath, newFileName)

Copy a file in various methods. If file exists, will fail to copy.

Param Type Details
path string

Base FileSystem. Please refer to the iOS and Android filesystems above

fileName string

Name of file to copy

newPath string

Base FileSystem of new location

newFileName string

New name of file to copy to (leave blank to remain the same)

Returns: Returns a Promise that resolves or rejects with an error.

API

Native

General