aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/filesystemdirectoryentry/index.html
blob: 22b7a7aeef07e56d8c9e30bfbf4e69fbdbd4f75b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: FileSystemDirectoryEntry
slug: Web/API/FileSystemDirectoryEntry
translation_of: Web/API/FileSystemDirectoryEntry
---
<p>{{APIRef("File System API")}}{{Non-standard_header}}</p>

<p><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">文件和目录条目 API</a> 的 <strong><code>FileSystemDirectoryEntry</code></strong> 接口表示文件系统中的目录。它提供了方法,使其能够访问和操作目录中的文件,以及访问目录中的条目。</p>

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

<h2 id="basic_concepts" name="basic_concepts">基本概念</h2>

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

<h3 id="example" name="example">示例</h3>

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

<pre class="brush: js">// 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);</pre>

<h2 id="属性">属性</h2>

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

<h2 id="方法">方法</h2>

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

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

<h3 id="废弃的方法">废弃的方法</h3>

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

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('File System API')}}</td>
   <td>{{Spec2('File System API')}}</td>
   <td>Draft of proposed API</td>
  </tr>
 </tbody>
</table>

<p>这个 API 没有官方的  W3C 或者 WHATWG 规范。</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>

{{Compat("api.FileSystemDirectoryEntry")}}

<h2 id="另见">另见</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API">文件和目录条目 API</a></li>
 <li><a href="/en-US/docs/Web/API/File_and_Directory_Entries_API/Introduction">文件系统 API 简介</a></li>
 <li>{{domxref("FileSystemDirectoryReader")}}</li>
 <li>{{domxref("FileSystemEntry")}}</li>
 <li>{{domxref("FileSystemFileEntry")}}</li>
</ul>