From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/filesystemdirectoryentry/index.html | 199 +++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 files/zh-cn/web/api/filesystemdirectoryentry/index.html (limited to 'files/zh-cn/web/api/filesystemdirectoryentry/index.html') diff --git a/files/zh-cn/web/api/filesystemdirectoryentry/index.html b/files/zh-cn/web/api/filesystemdirectoryentry/index.html new file mode 100644 index 0000000000..b6656c5de3 --- /dev/null +++ b/files/zh-cn/web/api/filesystemdirectoryentry/index.html @@ -0,0 +1,199 @@ +--- +title: FileSystemDirectoryEntry +slug: Web/API/FileSystemDirectoryEntry +translation_of: Web/API/FileSystemDirectoryEntry +--- +

{{APIRef("File System API")}}{{Non-standard_header}}

+ +

文件和目录条目 API 的 FileSystemDirectoryEntry 接口表示文件系统中的目录。它提供了方法,使其能够访问和操作目录中的文件,以及访问目录中的条目。

+ +
+

由于这是个非标准的 API,它的规范当前并没有在标准进程中,重要的是要记住,并不是所有浏览器都实现了他,并且实现它的浏览器可能仅仅实现了一小部分。更多细节请查看 {{anch("Browser compatibility")}} 。

+
+ +

基本概念

+ +

你可以通过调用 {{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}} 创建新的目录。如果你打算创建子目录,按需创建每个子目录。如果你尝试使用完整路径创建目录,包含不存在的父目录,会返回错误。所以需要在创建父目录之后,递归添加新的路径来创建层次。

+ +

示例

+ +

下面的代码中,我们创建了一个叫做 "Documents" 的目录。

+ +
// Taking care of the browser-specific prefixes.
+window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
+window.directoryEntry = window.directoryEntry || window.webkitDirectoryEntry;
+
+...
+
+function onFs(fs){
+  fs.root.getDirectory('Documents', {create:true}, function(directoryEntry){
+    //directoryEntry.isFile === false
+    //directoryEntry.isDirectory === true
+    //directoryEntry.name === 'Documents'
+    //directoryEntry.fullPath === '/Documents'
+
+    }, onError);
+
+  }
+
+// Opening a file system with temporary storage
+window.requestFileSystem(TEMPORARY, 1024*1024 /*1MB*/, onFs, onError);
+ +

属性

+ +

这个接口没有自己的属性,但是从它的父接口 {{domxref("FileSystemEntry")}} 继承了属性。

+ +

方法

+ +

这个接口从它的父接口 {{domxref("FileSystemEntry")}} 继承了方法。

+ +
+
{{domxref("FileSystemDirectoryEntry.createReader", "createReader()")}}
+
创建 {{domxref("FileSystemDirectoryReader")}} 对象,它可以用于服务目录中的条目。
+
{{domxref("FileSystemDirectoryEntry.getDirectory", "getDirectory()")}}
+
返回 {{domxref("FileSystemDirectoryEntry")}} 对象,表示位于给定路径的目录,相对于方法调用处的目录。
+
{{domxref("FileSystemDirectoryEntry.getFile", "getFile()")}}
+
返回 {{domxref("FileSystemFileEntry")}}对象,表示在目录层次中的一个文件,提供相对于方法调用处目录的路径。 
+
+ +

废弃的方法

+ +
+
{{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}}
+
删除目录和所有内容,包含子目录的内容。它已经从规范中移除。
+
+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('File System API')}}{{Spec2('File System API')}}Draft of proposed API
+ +

这个 API 没有官方的  W3C 或者 WHATWG 规范。

+ +

浏览器兼容性

+ +

{{ CompatibilityTable }}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeEdgeFirefox (Gecko)Internet ExplorerMicrosoft EdgeOperaSafari (WebKit)
Basic support13 {{ property_prefix("webkit") }}{{CompatVersionUnknown}}{{ CompatGeckoDesktop(50) }}[2]{{ CompatNo }}{{CompatNo}}[3]{{ CompatNo }}{{ CompatNo }}
removeRecursively()13 {{ property_prefix("webkit") }}{{CompatUnknown}}{{ CompatNo }}[1]{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
getFile() and getDirectory()13 {{ property_prefix("webkit") }}{{CompatUnknown}}{{ CompatGeckoDesktop(50) }}[2]{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{ CompatNo }}0.16 {{ property_prefix("webkit") }}{{CompatVersionUnknown}}{{ CompatGeckoDesktop(50) }}[2]{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
removeRecursively(){{ CompatNo }}0.16 {{ property_prefix("webkit") }}{{CompatUnknown}}{{ CompatNo }}[1]{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
getFile() and getDirectory(){{ CompatNo }}0.16 {{ property_prefix("webkit") }}{{CompatUnknown}}{{ CompatGeckoDesktop(50) }}[2]{{ CompatNo }}{{ CompatNo }}{{ CompatNo }}
+
+ +

[1] 虽然 {{domxref("FileSystemDirectoryEntry.removeRecursively", "removeRecursively()")}} 方法存在于 Firefox 50,它所做的所有事情就是使用 NS_ERROR_DOM_SECURITY_ERR 调用错误回调。它已经从 Firefox 52 中移除了,并且也从规范中移除。

+ +

[2] 在 Firefox 中,错误回调的参数是 {{domxref("DOMException")}} ,而不是 {{domxref("FileError")}} 对象。

+ +

[3] Microsoft Edge 在 WebKitEntry 接口中实现了这个接口的功能,它就是 {{domxref("FileSystemEntry")}}。

+ +

另见

+ + -- cgit v1.2.3-54-g00ecf