FileSystemDirectoryEntry

FileSystemDirectoryEntryファイルとディレクトリー項目 API のインターフェイスで、ファイルシステム内のディレクトリーを表します。これはディレクトリー内のファイルにアクセスして操作する方法と、ディレクトリー内のエントリーにアクセスする方法を提供します。

FileSystemEntry FileSystemDirectoryEntry

基本概念

getDirectory() を呼び出して新しいディレクトリーを作成することができます。サブディレクトリーを作成する場合は、各子ディレクトリーを順番に作成します。まだ存在しない親ディレクトリーを含むフルパスを使用してディレクトリーを作成しようとすると、エラーが返されます。したがって、親ディレクトリーを作成した後、新しいパスを再帰的に追加して階層を作成します。

次のコードスニペットでは、 "Documents" というディレクトリーを作成します。

js
// ブラウザー固有の接頭辞を取る
window.requestFileSystem =
  window.requestFileSystem || window.webkitRequestFileSystem;
window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;

// …

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

// 一時記憶装置でファイルシステムを開く
window.requestFileSystem(TEMPORARY, 1024 * 1024 /*1MB*/, onFs, onError);

プロパティ

このインターフェイスは独自のプロパティを持っていませんが、親インターフェイス FileSystemEntry からプロパティを継承しています。

メソッド

このインターフェイスは、親インターフェイスである FileSystemEntry からメソッドを継承しています。

createReader()

このディレクトリー内のエントリーを読み込むために使用できる FileSystemDirectoryReader オブジェクトを作成します。

getDirectory()

メソッドが呼び出されるディレクトリーを基準に、指定されたパスにあるディレクトリーを表す FileSystemDirectoryEntry オブジェクトを返します。

getFile()

メソッドが呼び出されるディレクトリーに対する相対パスを指定して、ディレクトリーの階層内にあるファイルを表す FileSystemFileEntry オブジェクトを返します。

仕様書

Specification
File and Directory Entries API
# api-directoryentry

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
FileSystemDirectoryEntry
createReader
getDirectory
getFile
removeRecursively
DeprecatedNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.

関連情報