非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

FileSystemEntrySync interface of the File and Directory Entries API represents an entry in a file system; it can be either a FileEntrySync or DirectoryEntry . It 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.

警告 : This API was never accepted and never became standardized. Various browsers implement pieces of the 文件和目录条目 API (otherwise known as the File System API) but you should try to avoid using it.

基本概念

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: .

可以使用 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 http://ww.html5rocks.com , 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.

方法概述

元数据 getMetadata () raises ( FileException );
FileSystemEntrySync moveTo (in DirectoryEntrySync parent , optional DOMString newName ) raises ( FileException );
FileSystemEntrySync copyTo (in DirectoryEntrySync parent , optional DOMString newName ) raises ( FileException );
DOMString toURL ();
void remove () raises ( FileException );
DirectoryEntrySync getParent ();

属性

属性 类型 描述
filesystem readonly FileSystemSync The file system where the entry resides.
fullpath readonly DOMString

The full absolute path from the root to the entry.

An absolute path is a relative path from the root directory, prepended with a ' / '.

isDirectory readonly boolean True if FileSystemEntrySync is a directory.
isFile readonly boolean True if the FileSystemEntrySync is a file.
名称 readonly DOMString The name of the entry, excluding the path leading to it.

方法

getMetadata()

Look up metadata about this entry. [ todo: specify what kind of metadata ]

Metadata getMetada ()
  raises (FileException);
						
参数
None
返回
元数据
异常

This method can raise a FileException with the following codes:

异常 描述
NOT_FOUND_ERR The entry does not exist.
INVALID_STATE_ERR The FileSystemSync is no longer valid for some reason besides being deleted.

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 参数。

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);
						
参数
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.

返回
FileSystemEntrySync

An object that represents an entry in the file system.

异常

This method can raise a FileException with the following codes:

异常 描述
ENCODING_ERR The name supplied is invalid, because at least one of the characters is reserved or illegal. Examples include a backslash (\), dot (.), and two dots (..).
NOT_FOUND_ERR The target directory does not exist.
INVALID_MODIFICATION_ERR You tried one of the following disallowed operations:

  • Moving an entry into its parent without changing its name
  • Moving a parent directory into one of its child directories. [todo: verify ]
NO_MODIFICATION_ALLOWED_ERR One of the following is not writable: the source entry, its parent directory, and the target directory.

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 simply duplicated.

void copyTo (
  in DirectoryEntrySync parent, optional DOMString newName
) raises (FileException);
					
参数
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.

返回
FileSystemEntrySync

An object that represents an entry in the file system.

异常

This method can raise a FileException with the following codes:

异常 描述
ENCODING_ERR The name supplied is invalid, because at least one of the characters is reserved or illegal. Examples include a backslash (\), dot (.), and two dots (..).
NOT_FOUND_ERR The target directory does not exist.
INVALID_MODIFICATION_ERR You tried one of the following disallowed operations:

  • Moving an entry into its parent without changing its name
  • Moving a parent directory into one of its child directories.
NO_MODIFICATION_ALLOWED_ERR One of the following is not writable: the source entry, its parent directory, and the target directory.
QUOTA_EXCEEDED_ERR The operation would cause the application to exceed its storage quota. You can ask for a larger persistent storage, which your user must explicitly grant. For more information, see the article on basic concepts .

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 ,调用 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 ();
				
参数
None.
返回
DOMString
异常

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() 代替。

void remove (
) raises (FileException);
				
参数

None

返回
void
异常

This method can raise a FileException with the following codes:

异常 描述
NOT_FOUND_ERR The target directory does not exist.
INVALID_MODIFICATION_ERR You tried to remove a directory that is not empty. If you want to remove an empty directory, use removeRecursively() 代替。
NO_MODIFICATION_ALLOWED_ERR One of the following is not writable: the source entry, its parent directory, and the target directory.

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 ();
				
参数

None

返回
DirectoryEntrySync

An object that represents a directory in the file system.

异常

None.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

No compatibility data found. Please contribute data for "api.FileSystemEntrySync" (depth: 1) to the MDN 兼容性数据存储库 .

另请参阅

规范: File API: Directories and System Specification WD

参考: 文件系统 API

介绍: Basic Concepts About the File System API

元数据

  • 最后修改: