FileSystemDirectoryEntry - Web APIs 编辑

Experimental

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The FileSystemDirectoryEntry interface of the File and Directory Entries API represents a directory in a file system. It provides methods which make it possible to access and manipulate the files in a directory, as well as to access the entries within the directory.

Basic concepts

You can create a new directory by calling getDirectory(). If you want to create subdirectories, create each child directory in sequence. If you try creating a directory using a full path that includes parent directories that do not exist yet, an error is returned. So create the hierarchy by recursively adding a new path after creating the parent directory.

Example

In the following code snippet, we create a directory called "Documents."

// Taking care of the browser-specific prefixes.
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;

...

function onFs(fs){
  fs.root.getDirectory('Documents', {create:true}, function(directoryEntry){
    //directoryEntry.isFile === false
    //directoryEntry.isDirectory === true
    //directoryEntry.name === 'Documents'
    //directoryEntry.fullPath === '/Documents'

    }, onError);

  }

// Opening a file system with temporary storage
window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);

Properties

This interface has no properties of its own, but inherits properties from its parent interface, FileSystemEntry.

Methods

This interface inherits methods from its parent interface, FileSystemEntry.

createReader()
Creates a FileSystemDirectoryReader object which can be used to read the entries in this directory.
getDirectory()
Returns a FileSystemDirectoryEntry object representing a directory located at a given path, relative to the directory on which the method is called.
getFile()
Returns a FileSystemFileEntry object representing a file located within the directory's hierarchy, given a path relative to the directory on which the method is called.

Obsolete methods

removeRecursively()
Deletes a directory and all of its contents, including the contents of subdirectories. This has been removed from the spec.

Specifications

SpecificationStatusComment
File and Directory Entries API
The definition of 'FileSystemDirectoryEntry' in that specification.
Draft

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:72 次

字数:5484

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文