FileSystemHandle.kind
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
FileSystemHandle
の読み取り専用プロパティ kind
は、エントリーの種類を返します。'file'
(対応するエントリーがファイルである場合) または 'directory'
が返ります。これは、ディレクトリーの中身について反復するとき、ファイルとディレクトリーを区別するために用いられます。
値
以下の値を取りうる文字列です。
'file'
: ハンドルがFileSystemFileHandle
の場合'directory'
: ハンドルがFileSystemDirectoryHandle
の場合
例
以下の関数は、ユーザーにファイルピッカーでファイルを選択させ、返されたハンドルがファイルかディレクトリーかを調べます。
js
// ファイルハンドルへの参照を保存する
let fileHandle;
async function getFile() {
// ファイルピッカーを開く
[fileHandle] = await window.showOpenFilePicker();
if (fileHandle.kind === "file") {
// ファイルの場合のコードを実行する
} else if (fileHandle.kind === "directory") {
// ディレクトリーの場合のコードを実行する
}
}
仕様書
Specification |
---|
File System # ref-for-dom-filesystemhandle-kind① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
kind |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
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.