The filesystem is represented as an abstract collection of disjointed filesystem virtual root locations, each corresponding to a specific location in the device filesystem. The filesystem API exposes the hierarchies below these root locations as a single virtual filesystem, but provides no access to other parts of the device filesystem.
Each virtual root has a string name. Each file or directory within the virtual filesystem is addressed using a fully-qualified path of the form: <root name>/<path> where <rootname> is the name of the virtual root and <path> is the path to the file or directory relative to that root.
The following virtual roots must be supported:
The file URI path is also supported. To access other paths out of virtual root, for example 'file:///tmp' can be used as location parameter.
To access specific locations apart from those specified above, a file handle must be retrieved using the filesystem.resolve() call.
A file handle represents either a file or a directory:
A file can be opened for both read and write operations, using a FileStream handle. A list of files and sub-directories can be obtained from a directory and a resolve method exists to resolve files or sub-directories more conveniently than processing directory listings.
The implementation must support the use of the following characters in file names:
The implementation may support additional characters in file names, depending on platform support.
The implementation may forbid the use of additional characters in file names, depending on the platform. The use of the path (component) separator "/" should not be allowed in file names.
Some other file name and path characteristics are platform-dependent, for example, maximum path length, file name length, case sensitivity, additional character support, etc. Therefore, it is recommended to avoid any dependency on aspects that cannot be supported across multiple platforms.
When a path is used to interact with the underlying filesystem, the encoding used for the file path should be the platform default.
For more information on the Filesystem features, see File System Guide.
Since: 2.4
Interface | Method |
---|---|
FileSystemManagerObject | |
FileSystemManager |
void resolve (DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode)
void getStorage (DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror)
void listStorages (FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror)
long addStorageStateChangeListener (FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror)
void removeStorageStateChangeListener (long watchId)
|
FileSystemStorage | |
File |
DOMString toURI ()
void listFiles (FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter)
void openStream (FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding)
void readAsText (FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding)
void copyTo (DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror)
void moveTo (DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror)
File createDirectory (DOMString dirPath)
File createFile (DOMString relativeFilePath)
void deleteDirectory (DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror)
void deleteFile (DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror)
|
FileFilter | |
FileStream |
void close ()
DOMString read (long charCount)
octet[] readBytes (long byteCount)
DOMString readBase64 (long byteCount)
void write (DOMString stringData)
void writeBytes (octet[] byteData)
void writeBase64 (DOMString base64Data)
|
FileSuccessCallback | |
FileSystemStorageArraySuccessCallback | void onsuccess (FileSystemStorage[] storages) |
FileSystemStorageSuccessCallback | void onsuccess (FileSystemStorage storage) |
FileStringSuccessCallback | void onsuccess (DOMString fileStr) |
FileStreamSuccessCallback | void onsuccess (FileStream filestream) |
FileArraySuccessCallback |
enum FileMode { "r", "rw", "w", "a" };
Since: 2.4
The file modes defined by this enumerator are:
enum FileSystemStorageType { "INTERNAL", "EXTERNAL" };
Since: 2.4
enum FileSystemStorageState { "MOUNTED", "REMOVED", "UNMOUNTABLE" };
Since: 2.4
[NoInterfaceObject] interface FileSystemManagerObject { readonly attribute FileSystemManager filesystem; };
Tizen implements FileSystemManagerObject;
Since: 2.4
There is a tizen.filesystem object that allows accessing the functionality of the Filesystem API.
[NoInterfaceObject] interface FileSystemManager { readonly attribute long maxPathLength; void resolve(DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode) raises(WebAPIException); void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void removeStorageStateChangeListener(long watchId) raises(WebAPIException); };
Since: 2.4
This manager interface exposes the Filesystem base API, and provides functionalities, such as determining root and default locations, resolving a given location into a file handle, and registering filesystem listeners for filesystem events.
Code example:
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name */ } var testFile = documentsDir.createFile("test.txt"); if (testFile != null) { testFile.openStream("w", function(fs) { fs.write("HelloWorld"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
Since: 2.4
Code example:
console.log("The maximum path length is " + tizen.filesystem.maxPathLength);
resolve
void resolve(DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode);
Since: 2.4
A location can contain a virtual path like 'documents/some_file.txt' or a file URI like 'file:///my_strange_path/some_file.png'. A location is not allowed to contain the "." or ".." substrings in its value.
The list of root locations that must be supported by a compliant implementation are:
The mode parameter specifies whether the resulting File object has read-only access ("r" access), read and write access ("rw" access), append access ("a" access), or write access ("w" access) to the root location containing directory tree. Permission for the requested access is obtained from the security framework. Once the resulting File object has access, access is inherited by any other File objects that are derived from this instance without any further reference to the security framework, as noted in descriptions of certain methods of File.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Remark : camera location is supported since Tizen 2.4. If a device does not support camera, NotSupportedError will be thrown.
Parameters:
Exceptions:
with error type TypeMismatchError, if any of the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type NotSupportedError, if this feature is not supported (e.g. in the case of 'camera' virtual path if the device does not support camera)
Code example:
tizen.filesystem.resolve('images', function(dir) { console.log("Mount point Name is " + dir.path); }, function(e) { console.log("Error: " + e.message); }, "r");
getStorage
void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The onsuccess method receives the data structure as an input argument containing additional information about the drive.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function onStorage(storage) { /* Do something */ } function onStorageError(e) { console.log("Storage not found!" + e.message); } tizen.filesystem.getStorage("music", onStorage, onStorageError);
listStorages
void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror);
Since: 2.4
Labels can differ depending on platform implementation.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function alertForCorruptedRemovableDrives(storages) { for (var i = 0; i < storages.length; i++) { if (storages[i].type != "EXTERNAL") continue; if (storages[i].state == "UNMOUNTABLE") console.log("External drive " + storages[i].label + " is corrupted."); } } tizen.filesystem.listStorages(alertForCorruptedRemovableDrives);
addStorageStateChangeListener
long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The most common usage for this method is to watch for any additions and removals of external storages.
When executed, it returns a subscription identifier that identifies the watch operation. After returning the identifier, the watch operation is started asynchronously. The onsuccess method will be invoked every time a storage state changes. If the attempt fails, the onerror if present will be invoked with the relevant error type.
The watch operation must continue until the removeStorageStateChangeListener() method is called with the corresponding subscription identifier.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
long Subscription identifierExceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var watchID; function onStorageStateChanged(storage) { if (storage.state == "MOUNTED") console.log("Storage " + storage.label + " was added!"); } watchID = tizen.filesystem.addStorageStateChangeListener(onStorageStateChanged);
removeStorageStateChangeListener
void removeStorageStateChangeListener(long watchId);
Since: 2.4
If the watchId argument is valid and corresponds to a subscription already in place, the watch process will be stopped and no further callbacks will be invoked. Otherwise, the method call has no effect.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var watchID; function onStorageStateChanged(storage) { if (storage.state == "MOUNTED") console.log("Storage " + storage.label + " was added!"); tizen.filesystem.removeStorageStateChangeListener(watchID); } watchID = tizen.filesystem.addStorageStateChangeListener(onStorageStateChanged);
[NoInterfaceObject] interface FileSystemStorage { readonly attribute DOMString label; readonly attribute FileSystemStorageType type; readonly attribute FileSystemStorageState state; };
Since: 2.4
To retrieve the mount point, the resolve() method should be used using the label as argument.
This attribute is used as an input for methods such as getStorage() and also used as location parameter for File.resolve() and FileSystemManager.resolve().
Since: 2.4
Since: 2.4
Since: 2.4
[NoInterfaceObject] interface File { readonly attribute File? parent; readonly attribute boolean readOnly; readonly attribute boolean isFile; readonly attribute boolean isDirectory; readonly attribute Date? created; readonly attribute Date? modified; readonly attribute DOMString path; readonly attribute DOMString name; readonly attribute DOMString fullPath; readonly attribute unsigned long long fileSize; readonly attribute long length; DOMString toURI() raises(WebAPIException); void listFiles(FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter) raises(WebAPIException); void openStream(FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void readAsText(FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void copyTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void moveTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); File createDirectory(DOMString dirPath) raises(WebAPIException); File createFile(DOMString relativeFilePath) raises(WebAPIException); File resolve(DOMString filePath) raises(WebAPIException); void deleteDirectory(DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void deleteFile(DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); };
Since: 2.4
The file object permissions for the file object location and tree rooted at that location depends upon the mode defined in the resolve method. When a File object creates a child File object, the new File object inherits its access rights from the parent object without any reference to the security framework, as noted in certain methods of File.
A file handle representing a file can be opened for I/O operations, such as reading and writing.
A file handle representing a directory can be used for listing all files and directories rooted as the file handle location.
Code example:
function onsuccess(files) { for (var i = 0; i < files.length; i++) { /* Alerts each name of dir's contents */ console.log(files[i].name); } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } /* List directory contents */ dir.listFiles(onsuccess, onerror);
This attribute is set tonull if there is no parent directory. This also implies that this directory represents a root location.
Since: 2.4
Code example:
/* List directory contents */ dir.listFiles(onsuccess, onerror); function onsuccess(files) { for (var i = 0; i < files.length; i++) { /* Prints the file parent, should contain the same value for all the files in the loop */ console.log("All the files should have the same parent " + files[i].parent); } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); }
This attribute is set to:
This attribute represents the actual state of a file or directory in the filesystem. Its value is not affected by the mode used in FileSystemManager.resolve() that was used to create the File object from which this File object was obtained.
Since: 2.4
Code example:
/* Lists directory contents */ dir.listFiles(onsuccess, onerror); function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].readOnly) console.log("Cannot write to file " + files[i].name); else console.log("Can write to file " + files[i].name); } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); }
This attribute can have the following values:
Since: 2.4
This attribute can have the following values:
Since: 2.4
This timestamp is equivalent to the timestamp when a call to createFile() succeeds.
If the platform does not support this attribute, it will be null.
It is unspecified and platform-dependent if the creation timestamp changes when a file is moved.
Since: 2.4
Opening a file for reading does not change the modification timestamp.
If the platform does not support this attribute, it will be null.
It is unspecified and platform-dependent if the modified timestamp changes when a file is moved.
Since: 2.4
Code example:
console.log(file.modified); /* Displays the modification timestamp */
It begins with the name of the root containing the file, followed by the path, including the directory containing the file, but excluding the file name.
Except in some special cases of the File representing the root itself, the last character is always '/'.
For example, if a file is located at music/ramones/volume1/RockawayBeach.mp3, the path is music/ramones/volume1/.
For example, if a directory is located at music/ramones/volume1, the path is music/ramones/.
For the virtual roots, the path is same as the name of the virtual root. For example, if the root is music, then the path is music. If the root is documents, then the path is documents.
Since: 2.4
Code example:
console.log(file.path); /* Must be 'music/' if the file is music/foo.mp3 */
This is the name of this file, excluding the root name and any other path components.
For example, if a file is located at music/ramones/volume1/RockawayBeach.mp3, the name is 'RockawayBeach.mp3'.
For example, if a directory is located at music/ramones/volume1, the name is be 'volume1'.
For the special case of the root itself, the name is an empty string.
Since: 2.4
Code example:
/* Must be foo.mp3 if the file path is music/foo.mp3 */ console.log(file.name);
It begins with the name of the root containing the file, and including the name of the file or directory itself.
For instance, if the RockawayBeach.mp3 file is located at music/ramones/volume1/, then the fullPath is music/ramones/volume1/RockawayBeach.mp3.
For a directory, if the volume1 directory is located at music/ramones/, then the fullPath is music/ramones/volume1.
For the special case of the root itself, if the root is music, then the fullPath is music.
The fullPath is always equal to path + name.
Since: 2.4
Code example:
/* Must be music/track1.mp3 if the file is music/track1.mp3 */ console.log(file.fullPath);
If an attempt to read this attribute for a directory is made, undefined is returned. To retrieve the number of files and directories contained in the directory, use the length attribute.
Since: 2.4
Code example:
/* Displays the file size */ console.log(file.fileSize);
If an attempt to read this attribute for a file is made, undefined is returned. To retrieve the size of a file, use the fileSize attribute.
Since: 2.4
Code example:
/* '3' if the directory contains two files and one sub-directory */ console.log(file.length);
toURI
DOMString toURI();
Since: 2.4
If that URI corresponds to any of the public virtual roots (that is images, videos, music, documents, and downloads) the URI must be globally unique and could be used by any widget.
If that URI corresponds to a file located in any a widget's private areas (such as wgt-package, wgt-private, wgt-private-tmp), the generated URI must be unique for that file and for the widget making the request (such as including some derived from the widget ID in the URI). These URIs must not be accessible to other widgets, apart from the one invoking this method.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Return value:
DOMString URI that identifies the file or null if an error occursExceptions:
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurred.
Code example:
tizen.filesystem.resolve('music/ramones/RockawayBeach.mp3', function(file) { var audio = new Audio(file.toURI()); audio.play(); console.log(file.toURI()); });
listFiles
void listFiles(FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter);
Since: 2.4
The list of files is passed as a File[] in onsuccess() and contains directories and files. However, the directories "." and ".." must not be returned. Each File object that is part of the array must inherit all the access rights (that is, one of the values in FileMode) from the File object in which this method is invoked.
If the filter is passed and contains valid values, only those directories and files in the directory that match the filter criteria specified in the FileFilter interface must be returned in the onsuccess() method. If no filter is passed, the filter is null or undefined, or the filter contains invalid values, the implementation must return the full list of files in the directory.
If the directory does not contain any files or directories, or the filter criteria does not matched with any files or directories, the onsuccess() is invoked with an empty array.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function onsuccess(files) { console.log("There are " + files.length + " in the selected folder"); } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "r");
openStream
void openStream(FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding);
Since: 2.4
This operation is performed asynchronously. If the file is opened successfully, the onsuccess() method is invoked with a FileStream that can be used for reading and writing the file, depending on the mode. The returned FileStream instance includes a file pointer, which represents the current position in the file. The file pointer, by default, is at the start of the file, except in the case of opening a file in append ("a") mode, in which case the file pointer points to the end of the file.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name */ } var testFile = documentsDir.createFile("test.txt"); if (testFile != null) { testFile.openStream("w", function(fs) { fs.write("HelloWorld"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
readAsText
void readAsText(FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding);
Since: 2.4
If the operation is successfully executed, the onsuccess() method is invoked and a DOMString is passed as input parameter that represents the file content in the format determined by the encoding parameter.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name */ if (files[i].isDirectory == false) { files[i].readAsText(function(str) { console.log("The file content " + str); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } var documentsDir; tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
copyTo
void copyTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The copy of the file or directory identified by the originFilePath parameter must be created in the path passed in the destinationFilePath parameter.
The file or directory to copy must be under the Directory from which the method is invoked, otherwise the operation must not be performed.
If the copy is performed successfully, the onsuccess() method is invoked.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory == false) { documentsDir.copyTo(files[i].fullPath, "images/backup/" + files[i].name, false, function() {console.log("file copied");}); } } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
moveTo
void moveTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Since: 2.4
The file or directory identified by the originFilePath parameter is moved to the path passed in the destinationFilePath parameter.
The file to move must be under the directory from which the method is invoked, else the operation can not be performed.
If the file or directory is moved successfully, the onsuccess() method is invoked.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory == false) { documentsDir.moveTo(files[i].fullPath, "images/newFolder/" + files[i].name, false, function() {console.log("file moved");}); } } } function onerror(error) { console.log("The error " + error.message + " occurred during listing the files in the selected folder"); } tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
createDirectory
File createDirectory(DOMString dirPath);
Since: 2.4
A new directory will be created relative to the current directory that this operation is performed on. The implementation will attempt to create all necessary sub-directories specified in the dirPath, as well. The use of "." or ".." in path components is not supported.
This operation can only be performed on file handlers that represent a directory (that is, isDirectory == true).
If the directory is successfully created, it will be returned.
In case the directory cannot be created, an error must be thrown with the appropriate error type.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
File File handle of the new directory. The new File object has "rw" access rights, as it inherits this from the File object on which the createDirectory() method is called.Exceptions:
with error type IOError, if the dirPath already exists, if the file in which the createDirectory() method is invoked is a file (and not a directory).
with error type InvalidValuesError, if the dirPath does not contain a valid path.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var dir; /* Directory object obtained from filesystem API */ var newDir = dir.createDirectory("newDir"); var anotherNewDir = dir.createDirectory("newDir1/subNewDir1");
createFile
File createFile(DOMString relativeFilePath);
Since: 2.4
The use of "." or ".." in path components is not supported. This operation can only be performed on file handlers that represent a directory (that is, isDirectory == true).
If the file is successfully created, a file handler must be returned by this method.
In case the file cannot be created, an error must be thrown with the appropriate error type.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Return value:
File File handle for the new empty file. The new File object has "rw" access rights, as it inherits this from the File object on which the createFile() method is called.Exceptions:
with error type IOError, if the filePath already exists, if the File in which the createFile() method is invoked is a file (not a directory).
with error type InvalidValuesError, if the filePath contains an invalid value.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var newFile = dir.createFile("newFilePath");
resolve
File resolve(DOMString filePath);
Since: 2.4
The filePath is not allowed to contain the "." or ".." substrings in its value.
The encoding of file paths is UTF-8.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
File File handle of the file. The new File object inherits its access rights from the File object on which this resolve() method is called.Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if the file path contains an invalid value.
with error type IOError, if the method is executed in a File object that does not represent a directory (that is, isDirectory attribute is false).
with error type NotFoundError, if a file does not exist for the passed file path.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, if any other error occurs.
Code example:
var file; /* Resolves helloWorld.doc file that is located in the documents root location */ tizen.filesystem.resolve('documents', function(dir) { file = dir.resolve("helloWorld.doc"); }, function(e) { console.log("Error" + e.message); }, "rw");
deleteDirectory
void deleteDirectory(DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Since: 2.4
This method attempts to asynchronously delete a directory or directory tree under the current directory.
If the recursive parameter is set to true, all the directories and files under the specified directory must be deleted. If the recursive parameter is set to false, the directory is only deleted if it is empty, otherwise an IOError error type will be passed in onerror().
If the deletion is performed successfully, the onsuccess() is invoked.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (files[i].isDirectory) { documentsDir.deleteDirectory(files[i].fullPath, false, function() { console.log("Directory Deleted"); }, function(e) { console.log("Error" + e.message); }); } } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
deleteFile
void deleteFile(DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror);
Since: 2.4
If the deletion is performed successfully, the onsuccess() is invoked.
The ErrorCallback is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (!files[i].isDirectory) { documentsDir.deleteFile(files[i].fullPath, function() { console.log("File Deleted"); }, function(e) { console.log("Error" + e.message); }); } } } function onerror(error) { console.log("The error " + error.message + " occurred when listing the files in the selected folder"); } var documentsDir; tizen.filesystem.resolve('documents', function(dir) { documentsDir = dir; dir.listFiles(onsuccess,onerror); }, function(e) { console.log("Error" + e.message); }, "rw");
dictionary FileFilter { DOMString name; Date startModified; Date endModified; Date startCreated; Date endCreated; };
Since: 2.4
When this dictionary is passed in the listFiles() method, the result-set of the listFiles() method must only contain the file items entries that match the attribute values of the filter.
A file item only matches the FileFilter object if all the attributes of the file item match all the attribute values of the filter which are defined (that is, only matching values other than undefined or null). This is similar to an SQL "AND" operation.
An attribute of the file entry matches the FileFilter attribute value in accordance with the following rules:
Files that have a name that corresponds with this attribute (either exactly or with the specified wildcards) match this filtering criteria.
Since: 2.4
Files with modified date later than this attribute or equal to it match the filtering criteria.
Since: 2.4
Files with modified date earlier than this attribute or equal to it match the filtering criteria.
Since: 2.4
Files with created date later than this attribute or equal to it match the filtering criteria.
Since: 2.4
Files with created date earlier than this attribute or equal to it match the filtering criteria.
Since: 2.4
[NoInterfaceObject] interface FileStream { readonly attribute boolean eof; attribute long position setraises(WebAPIException); readonly attribute long bytesAvailable; void close(); DOMString read(long charCount) raises(WebAPIException); octet[] readBytes(long byteCount) raises(WebAPIException); DOMString readBase64(long byteCount) raises(WebAPIException); void write(DOMString stringData) raises(WebAPIException); void writeBytes(octet[] byteData) raises(WebAPIException); void writeBase64(DOMString base64Data) raises(WebAPIException); };
Since: 2.4
A series of read/write methods are available that permit both binary and text to be processed.
Once a file stream is closed, any operation attempt made on this stream results in a standard JavaScript error.
The read/write operations in this interface do not throw any security exceptions as the access rights are expected to be granted through the initial resolve() method or through the openStream() method of the File interface. Therefore, all actions performed on a successfully resolved File and FileStream are expected to succeed. This avoids successive asynchronous calls and may potentially increase application for a user.
If set to true, this attribute indicates that the file pointer is at the end of the file.
If set to false, this attribute indicates that the file pointer is not at the end of the file and so it is anywhere within the file.
Since: 2.4
Code example:
if (stream.eof) { /* File has been read completely */ }
The stream position is an offset of bytes from the start of the file stream. When invoking an operation that reads or writes from the stream, the operation will take place from the byte defined by this position attribute. If the read or write operation is successful, the position of the stream is advanced by the number of bytes read or written. If the read/write operation is not successful, the position of the stream is unchanged.
Since: 2.4
Code example:
console.log(stream.position); /* Displays current stream position */ /* Alters current stream position to the begin of the file, like seek() in C */ stream.position = 0;
The number of bytes available for reading is the maximum amount of bytes that can be read in the next read operation. It corresponds to the number of bytes available after the file pointer denoted by the position attribute.
-1 if EOF is true.
Since: 2.4
Code example:
console.log(stream.bytesAvailable); /* Displays the available bytes to be read */
close
void close();
Since: 2.4
Flushes any pending buffered writes and closes the File. Always succeeds. Note that pending writes might not succeed.
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Code example:
stream.close(); /* Closes this stream, no subsequent access to stream allowed */
read
DOMString read(long charCount);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
DOMString Array of read characters as a stringExceptions:
with error type IOError, if a read error occurs, such as the bytes in the stream cannot be decoded with the encoding in use.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var text = stream.read(file.fileSize); stream.close();
readBytes
octet[] readBytes(long byteCount);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
octet[] Result of read bytes as a byte (or number) arrayExceptions:
with error type IOError, if a read error occurs.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if this functionality is not allowed.
Code example:
/* Reads up to 256 bytes from the stream */ var raw = stream.readBytes(256); for (var i = 0; i < raw.length; i++) { /* raw[i] contains the i-th byte of the current data chunk */ }
readBase64
DOMString readBase64(long byteCount);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.read
Parameters:
Return value:
DOMString Array of read characters as base64 encoding string.Exceptions:
with error type IOError, if a read error occurs.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if this functionality is not allowed.
Code example:
/* Reads up to 256 bytes from the stream */ var base64 = stream.readBase64(256);
write
void write(DOMString stringData);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type IOError, if a write error occurs.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var text = "Hello world"; stream.write(text);
writeBytes
void writeBytes(octet[] byteData);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type IOError, if a write error occurs.
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var bytes = in.readBytes(256); /* Writes the bytes read from in to out */ out.writeBytes(bytes);
writeBase64
void writeBase64(DOMString base64Data);
Since: 2.4
Privilege level: public
Privilege: http://tizen.org/privilege/filesystem.write
Parameters:
Exceptions:
with error type IOError, if an error occurs during writeBase64.
with error type InvalidValuesError, if the input parameter contains an invalid value (e.g. the base64Data input parameter is not a valid Base64 sequence).
with error type SecurityError, if the application does not have the privilege to call this method.
Code example:
var base64 = in.readBase64(256); /* Writes the base64 data read from in to out */ out.writeBase64(base64);
[Callback=FunctionOnly, NoInterfaceObject] interface FileSuccessCallback { void onsuccess(File file); };
Since: 2.4
It is used in asynchronous operations, such as FileSystemManager.resolve(), copying, moving, and deleting files.
onsuccess
void onsuccess(File file);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageArraySuccessCallback { void onsuccess(FileSystemStorage[] storages); };
Since: 2.4
It is used in asynchronous operations, such as FileSystemManager.listStorages().
onsuccess
void onsuccess(FileSystemStorage[] storages);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageSuccessCallback { void onsuccess(FileSystemStorage storage); };
Since: 2.4
It is used in asynchronous operations, such as FileSystemManager.getStorage() and FileSystemManager.addStorageStateChangeListener().
onsuccess
void onsuccess(FileSystemStorage storage);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface FileStringSuccessCallback { void onsuccess(DOMString fileStr); };
Since: 2.4
It is used in asynchronous operations, such as File.readAsText().
[Callback=FunctionOnly, NoInterfaceObject] interface FileStreamSuccessCallback { void onsuccess(FileStream filestream); };
Since: 2.4
It is used by asynchronous methods, such as File.openStream().
onsuccess
void onsuccess(FileStream filestream);
Since: 2.4
Parameters:
[Callback=FunctionOnly, NoInterfaceObject] interface FileArraySuccessCallback { void onsuccess(File[] files); };
Since: 2.4
This callback interface specifies a success callback with a function taking an array of File objects as input argument. It is used in asynchronous methods, such as File.listFiles().
onsuccess
void onsuccess(File[] files);
Since: 2.4
Parameters:
module Filesystem { enum FileMode { "r", "rw", "w", "a" }; enum FileSystemStorageType { "INTERNAL", "EXTERNAL" }; enum FileSystemStorageState { "MOUNTED", "REMOVED", "UNMOUNTABLE" }; [NoInterfaceObject] interface FileSystemManagerObject { readonly attribute FileSystemManager filesystem; }; Tizen implements FileSystemManagerObject; [NoInterfaceObject] interface FileSystemManager { readonly attribute long maxPathLength; void resolve(DOMString location, FileSuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileMode? mode) raises(WebAPIException); void getStorage(DOMString label, FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void listStorages(FileSystemStorageArraySuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); long addStorageStateChangeListener(FileSystemStorageSuccessCallback onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void removeStorageStateChangeListener(long watchId) raises(WebAPIException); }; [NoInterfaceObject] interface FileSystemStorage { readonly attribute DOMString label; readonly attribute FileSystemStorageType type; readonly attribute FileSystemStorageState state; }; [NoInterfaceObject] interface File { readonly attribute File? parent; readonly attribute boolean readOnly; readonly attribute boolean isFile; readonly attribute boolean isDirectory; readonly attribute Date? created; readonly attribute Date? modified; readonly attribute DOMString path; readonly attribute DOMString name; readonly attribute DOMString fullPath; readonly attribute unsigned long long fileSize; readonly attribute long length; DOMString toURI() raises(WebAPIException); void listFiles(FileArraySuccessCallback onsuccess, optional ErrorCallback? onerror, optional FileFilter? filter) raises(WebAPIException); void openStream(FileMode mode, FileStreamSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void readAsText(FileStringSuccessCallback onsuccess, optional ErrorCallback? onerror, optional DOMString? encoding) raises(WebAPIException); void copyTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void moveTo(DOMString originFilePath, DOMString destinationFilePath, boolean overwrite, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); File createDirectory(DOMString dirPath) raises(WebAPIException); File createFile(DOMString relativeFilePath) raises(WebAPIException); File resolve(DOMString filePath) raises(WebAPIException); void deleteDirectory(DOMString directoryPath, boolean recursive, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); void deleteFile(DOMString filePath, optional SuccessCallback? onsuccess, optional ErrorCallback? onerror) raises(WebAPIException); }; dictionary FileFilter { DOMString name; Date startModified; Date endModified; Date startCreated; Date endCreated; }; [NoInterfaceObject] interface FileStream { readonly attribute boolean eof; attribute long position setraises(WebAPIException); readonly attribute long bytesAvailable; void close(); DOMString read(long charCount) raises(WebAPIException); octet[] readBytes(long byteCount) raises(WebAPIException); DOMString readBase64(long byteCount) raises(WebAPIException); void write(DOMString stringData) raises(WebAPIException); void writeBytes(octet[] byteData) raises(WebAPIException); void writeBase64(DOMString base64Data) raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileSuccessCallback { void onsuccess(File file); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageArraySuccessCallback { void onsuccess(FileSystemStorage[] storages); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileSystemStorageSuccessCallback { void onsuccess(FileSystemStorage storage); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileStringSuccessCallback { void onsuccess(DOMString fileStr); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileStreamSuccessCallback { void onsuccess(FileStream filestream); }; [Callback=FunctionOnly, NoInterfaceObject] interface FileArraySuccessCallback { void onsuccess(File[] files); }; };