FileSystemHandle: kind 屬性
注意:此功能在 Web Workers 中可用。
kind 是 FileSystemHandle 介面的只讀屬性,用於返回條目的型別。如果關聯的條目是檔案,則返回 'file';如果關聯的條目是目錄,則返回 'directory'。在遍歷目錄內容時,使用此屬性區分檔案和目錄。
值
一個字串,可以是
'file':如果控制代碼是FileSystemFileHandle。'directory':如果控制代碼是FileSystemDirectoryHandle。
示例
以下函式允許使用者從檔案選擇器中選擇一個檔案,然後測試返回的控制代碼是檔案還是目錄。
js
// store a reference to our file handle
let fileHandle;
async function getFile() {
// open file picker
[fileHandle] = await window.showOpenFilePicker();
if (fileHandle.kind === "file") {
// run file code
} else if (fileHandle.kind === "directory") {
// run directory code
}
}
規範
| 規範 |
|---|
| 檔案系統 # ref-for-dom-filesystemhandle-kind① |
瀏覽器相容性
載入中…