这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
FileSystemEntry
接口方法
getParent
()
obtains a
FileSystemDirectoryEntry
.
FileSystemEntry.getParent(successCallback[, errorCallback]);
successCallback
FileSystemDirectoryEntry
object representing the parent directory. The parent of the root directory is considered to be the root directory, itself, so be sure to watch for that.
errorCallback
可选
FileError
describing what went wrong.
FileError.INVALID_STATE_ERR
The operation failed because the file system's state doesn't permit it. This can happen, for example, if the file system's cached state differs from the actual state of the file system.
FileError.NOT_FOUND_ERR
The specified path could not be found.
FileError.SECURITY_ERR
Security restrictions prohibit obtaining the parent directory's information.
This example renames the file specified by the variable
fileEntry
to
"newname.html"
.
fileEntry.getParent(function(parent) {
fileEntry.moveTo(parent, "newname.html", function(updatedEntry) {
console.log("File " + fileEntry.name + " renamed to newname.html.");
});
}, function(error) {
console.error("An error occurred: Unable to rename " + fileEntry.name
+ " to newname.html.");
});
This is accomplished by first obtaining a
FileSystemDirectoryEntry
object representing the directory the file is currently located in. Then
moveTo()
is used to rename the file within that directory.
Currently, there isn't a
Promise
-based version of this method. You can, however, create a simple helper function to adapt it, like this:
function getParentPromise(entry) {
return new Promise((resolve, reject) => {
entry.getParent(resolve, reject);
});
}
A similar approach can be taken elsewhere in the File and Directory Entries API.
| 规范 | 状态 | 注释 |
|---|---|---|
|
文件和目录条目 API
The definition of 'getParent()' in that specification. |
草案 | 最初的规范。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getParent
|
Chrome 8 | Edge 79 | Firefox No | IE No | Opera No | Safari 11.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android No | Opera Android No | Safari iOS 11.3 | Samsung Internet Android Yes |
完整支持
不支持
实验。期望将来行为有所改变。
FileSystemEntry
copyTo()
getMetadata()
getParent()
moveTo()
remove()
toURL()
FileError
FileException
FileHandle
FileRequest
FileSystem
FileSystemDirectoryEntry
FileSystemDirectoryEntrySync
FileSystemDirectoryReader
FileSystemDirectoryReaderSync
FileSystemEntrySync
FileSystemFileEntry
FileSystemFileEntrySync
FileSystemFlags
FileSystemSync
HTMLInputElement
LocalFileSystem
LocalFileSystemSync
LockedFile
元数据
Window.requestFileSystem()
Window.resolveLocalFileSystemURL()
WorkerGlobalScope.requestFileSystemSync()