FileSystemDirectoryHandle: resolve() 方法
注意:此功能在 Web Workers 中可用。
FileSystemDirectoryHandle 接口的 resolve() 方法返回一个 Array,其中包含从父句柄到指定子条目的目录名称,子条目名称作为数组的最后一项。
语法
js
resolve(possibleDescendant)
参数
possibleDescendant-
要返回相对路径的
FileSystemHandle。
返回值
一个 Promise,它将解析为一个字符串 Array,或者如果 possibleDescendant 不是此 FileSystemDirectoryHandle 的后代,则解析为 null。
异常
不会抛出任何异常。
示例
以下异步函数使用 resolve() 方法查找相对于指定目录句柄的选定文件的路径。
js
async function returnPathDirectories(directoryHandle) {
// Get a file handle by showing a file picker:
const [handle] = await self.showOpenFilePicker();
if (!handle) {
// User cancelled, or otherwise failed to open a file.
return;
}
// Check if handle exists inside our directory handle
const relativePaths = await directoryHandle.resolve(handle);
if (relativePaths === null) {
// Not inside directory handle
} else {
// relativePath is an array of names, giving the relative path
for (const name of relativePaths) {
// log each entry
console.log(name);
}
}
}
规范
| 规范 |
|---|
| 文件系统 # api-filesystemdirectoryhandle-resolve |
浏览器兼容性
加载中…