非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
FileSystemEntry
interface of the File and Directory Entries API represents a single in a file system. The entry can be a file or a directory (directories are represented by the
DirectoryEntry
interface). It includes methods for working with files—including copying, moving, removing, and reading files—as well as information about a file it points to—including the file name and its path from the root to the entry.
由于这是非标准 API,其规范目前不在标准轨道中,所以记住并非所有浏览器都有实现且可能仅实现一小部分,这点很重要。检查 浏览器兼容性 章节了解细节。
不要创建
FileSystemEntry
objects directly. Instead, you will receive an object based on this interface through other APIs. This interface serves as a base class for the
FileSystemFileEntry
and
FileSystemDirectoryEntry
interfaces, which provide features specific to file system entries representing files and directories, respectively.
FileSystemEntry
interface includes methods that you would expect for manipulating files and directories, but it also includes a convenient method for obtaining the 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://www.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.
To see an example of how
toURL()
works, see the
method description
. The snippet below shows you how you can remove a file by name.
// Taking care of the browser-specific prefixes.
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
...
// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, function(fs) {
fs.root.getFile('log.txt', {}, function(fileEntry) {
fileEntry.remove(function() {
console.log('File removed.');
}, onError);
}, onError);
}, onError);
This interface provides the following properties.
filesystem
只读
FileSystem
object representing the file system in which the entry is located.
fullPath
只读
USVString
object which provides the full, absolute path from the file system's root to the entry; it can also be thought of as a path which is relative to the root directory, prepended with a "/" character.
isDirectory
只读
布尔
which is
true
if the entry represents a directory; otherwise, it's
false
.
isFile
只读
true
if the entry represents a file. If it's not a file, this value is
false
.
名称
只读
USVString
containing the name of the entry (the final part of the path, after the last "/" character).
This interface defines the following methods.
copyTo()
Copies the file or directory to a new location on the file system.
getMetadata()
Obtains metadata about the file, such as its modification date and size.
getParent()
FileSystemDirectoryEntry
representing the entry's parent directory.
moveTo()
Moves the file or directory to a new location on the file system, or renames the file or directory.
remove()
Removes the specified file or directory. You can only remove directories which are empty.
toURL()
"filesystem:"
.
| 规范 | 状态 | 注释 |
|---|---|---|
| 文件和目录条目 API | 草案 | 提议 API 草案 |
此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
FileSystemEntry
|
Chrome
8
Alternate Name
|
Edge
79
Prefixed
|
Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 |
WebView Android
≤37
Alternate Name
|
Chrome Android
18
Alternate Name
|
Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 |
Samsung Internet Android
Yes
Prefixed
|
copyTo
弃用
非标
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
filesystem
|
Chrome 8 | Edge 79 | Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
fullPath
|
Chrome 8 | Edge 79 | Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
getMetadata
弃用
非标
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
getParent
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
isDirectory
|
Chrome 8 | Edge 79 | Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
isFile
|
Chrome 8 | Edge 79 | Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
moveTo
弃用
非标
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
名称
|
Chrome 8 | Edge 79 | Firefox 50 | IE 不支持 No | Opera 不支持 No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 50 | Opera Android 不支持 No | Safari iOS 11.3 | Samsung Internet Android Yes |
remove
弃用
非标
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
toURL
弃用
非标
|
Chrome 8 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android ≤37 | Chrome Android 18 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android Yes |
完整支持
不支持
实验。期望将来行为有所改变。
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
使用非标名称。
要求使用供应商前缀或不同名称。
FileSystemFileEntry
and
FileSystemDirectoryEntry
are based on
FileSystemEntry
.
FileSystemEntry
FileError
FileException
FileHandle
FileRequest
FileSystem
FileSystemDirectoryEntry
FileSystemDirectoryEntrySync
FileSystemDirectoryReader
FileSystemDirectoryReaderSync
FileSystemEntrySync
FileSystemFileEntry
FileSystemFileEntrySync
FileSystemFlags
FileSystemSync
HTMLInputElement
LocalFileSystem
LocalFileSystemSync
LockedFile
元数据
Window.requestFileSystem()
Window.resolveLocalFileSystemURL()
WorkerGlobalScope.requestFileSystemSync()