FileSystemEntrySync
Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The FileSystemEntrySync
interface of the File and Directory Entries API represents an entry in a file system; it can be either a FileEntrySync
or FileSystemDirectoryEntry
.
This interface includes methods for working with files—including copying, moving, removing, and reading files—as well as information about the file it points to—including the file name and its path from the root to the entry.
Warning: This API was never accepted and never became standardized. Various browsers implement pieces of the File and Directory Entries API (otherwise known as the File System API) but you should try to avoid using it.
Basic concepts
The FileSystemEntrySync
interface includes methods that you would expect for manipulating files and directories, but it also include a really handy method for getting a URL of the entry: toURL()
. It also introduces a new URL scheme: filesystem:
.
You can use the filesystem:
scheme on Google Chrome to see all the files and folders that are stored in the origin of your app. Just use filesystem:
scheme for the root directory of the origin of the app. For example, if your app is in https://www.html5rocks.com/en/
, open filesystem:http://www.html5rocks.com/temporary/
in a tab. Chrome shows a read-only list of all the files and folders stored the origin of your app.
Method overview
Attributes
Methods
Look up metadata about this entry. [ todo: specify what kind of metadata ]
Metadata getMetadata()
raises (FileException);
Parameter
None
Returns
A Metadata
object.
Exceptions
This method can raise a FileException with the following codes:
moveTo()
Move an entry to a different location on the file system. Moving a file over an existing file replaces that existing file. Moving a directory over an existing empty directory replaces that directory. [todo: What if the directory is not empty? ]
[todo: Verify ] This is the same method for renaming files. You can keep it in the same location and then define the newName
parameter.
You cannot do the following:
- Move a directory inside itself or to any child at any depth
- Move an entry into its parent if a name different from its current one isn't provided
- Move a file to a path occupied by a directory or move a directory to a path occupied by a file
- Move any element to a path occupied by a directory that is not empty.
FileSystemEntrySync moveTo (
in DirectoryEntrySync parent, optional DOMString newName
) raises (FileException);
Parameters
- parent
-
The directory to which to move the entry.
- newName
-
The new name of the entry. If you do not specify a name, the browser preserves the entry's current name.
Returns
A FileSystemEntrySync
object.
Exceptions
This method can raise a FileException with the following codes:
copyTo()
Copy an entry to a different location on the file system. You cannot copy an entry inside itself if it is a directory, nor can you copy it into its parent without providing a new name. Directory copies are always recursive—that is, all contents of the directory are copied. You cannot change this behavior. Files are duplicated.
void copyTo (
in DirectoryEntrySync parent, optional DOMString newName
) raises (FileException);
Parameters
- parent
-
The directory where you want the entry to move to.
- newName
-
The new name of the entry. If you do not specify a name, the browser preserves the FileSystemEntrySync's current name.
Returns
A FileSystemEntrySync
object.
Exceptions
This method can raise a FileException with the following codes:
toURL()
Returns a URL that can be used to identify this entry. It exposes a new URL scheme—filesystem:
—that you can use to fill src
or href
attributes. For example, if you wanted to display an image and have its fileEntry, calling toURL()
gives you the image file's file system URL. You get something like: filesystem:http://example.com/temporary/lolcat.png.
The file system URL does not expire. Because the method describes a location on disk, the URL is valid for as long as that location exists. You can delete the file and recreate it, and it's all good.
You can supply the mimeType
to simulate the optional MIME type header associated with HTTP downloads.
DOMString toURL ();
Parameter
None.
Returns
A DOMString
object.
Exceptions
None
remove()
Deletes a file or directory. You cannot delete an empty directory or the root directory of a file system. If you want to remove an empty directory, use removeRecursively()
instead.
void remove (
) raises (FileException);
Parameter
None
Returns
None.
Exceptions
This method can raise a FileException with the following codes:
getParent()
Look up the parent DirectoryEntrySync
containing the entry. If this entry is the root of its file system, then the parent is itself.
void getParent ();
Parameter
None
Returns
DirectoryEntrySync
-
An object that represents a directory in the file system.
Exceptions
None.
Browser compatibility
See also