大网数据广告活动
Web 标准与前端开发

FileSystemEntry

· 52CE 我爱测

The **`FileSystemEntry`** interface of the File and Directory Entries API represents a single entry in a file system. The entry can be a file or a directory (directories are represented by the FileSystemDirectoryEntry interface). It includes methods for working with files—includi

File and Directory Entries API

The FileSystemEntry interface of the File and Directory Entries API represents a single entry in a file system. The entry can be a file or a directory (directories are represented by the FileSystemDirectoryEntry 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.

Instance properties

This interface provides the following properties.

  • FileSystemEntry.filesystem
    • : A FileSystem object representing the file system in which the entry is located.
  • FileSystemEntry.fullPath
    • : A string 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.
  • FileSystemEntry.isDirectory
    • : A boolean value which is true if the entry represents a directory; otherwise, it's false.
  • FileSystemEntry.isFile
    • : A Boolean which is true if the entry represents a file. If it's not a file, this value is false.
  • FileSystemEntry.name
    • : A string containing the name of the entry (the final part of the path, after the last "/" character).

Instance methods

This interface defines the following methods.

  • FileSystemEntry.copyTo
    • : Copies the file or directory to a new location on the file system.
  • FileSystemEntry.getMetadata
    • : Obtains metadata about the file, such as its modification date and size.
  • FileSystemEntry.getParent
    • : Returns a FileSystemDirectoryEntry representing the entry's parent directory.
  • FileSystemEntry.moveTo
    • : Moves the file or directory to a new location on the file system, or renames the file or directory.
  • FileSystemEntry.remove
    • : Removes the specified file or directory. You can only remove directories which are empty.
  • FileSystemEntry.toURL
    • : Creates and returns a URL which identifies the entry. This URL uses the URL scheme "filesystem:".

Description

You don't create 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.

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

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 http://www.example.com, open filesystem:http://www.example.com/temporary/ in a tab. Chrome shows a read-only list of all the files and folders stored the origin of your app.

Examples

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 */,
  (fs) => {
    fs.root.getFile(
      "log.txt",
      {},
      (fileEntry) => {
        fileEntry.remove(() => {
          console.log("File removed.");
        }, onError);
      },
      onError,
    );
  },
  onError,
);

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。