-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
65 lines (43 loc) · 2.42 KB
/
index.md
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
---
title: FileSystemDirectoryHandle.getDirectoryHandle()
slug: Web/API/FileSystemDirectoryHandle/getDirectoryHandle
l10n:
sourceCommit: 0444ab41bb372e63b3345f50e5b1e4e6a96c21d5
---
{{securecontext_header}}{{APIRef("File System Access API")}}
{{domxref("FileSystemDirectoryHandle")}} インターフェイスの **`getDirectoryHandle()`** メソッドは、このメソッドが呼ばれたディレクトリーハンドル内の指定した名前のサブディレクトリーを表す {{domxref('FileSystemDirectoryHandle')}} を返します。
## 構文
```js-nolint
getDirectoryHandle(name)
getDirectoryHandle(name, options)
```
### 引数
- `name`
- : 取得したいサブディレクトリーの {{domxref('FileSystemHandle.name')}} を表す文字列です。
- `options` {{optional_inline}}
- : 取得するサブディレクトリーに関するオプションを持つオブジェクトで、省略可能です。以下のオプションがあります。
- `create`
- : {{jsxref("boolean")}} 値で、デフォルトは `false` です。`true` に設定すると、ディレクトリーが見つからない場合、指定した名前のディレクトリーが作成されて返されます。
### 返値
{{domxref('FileSystemDirectoryHandle')}} で解決する {{jsxref('Promise')}} を返します。
### 例外
- `NotAllowedError` {{domxref("DOMException")}}
- : {{domxref('PermissionStatus')}} が `'granted'` でないとき投げられます。
- `TypeMismatchError` {{domxref("DOMException")}}
- : 返されるエントリーがファイルで、ディレクトリーではないとき投げられます。
- `NotFoundError` {{domxref("DOMException")}}
- : ディレクトリーが存在せず、`create` オプションが `false` に設定されているとき投げられます。
## 例
以下の例では、指定した名前のディレクトリーハンドルを返します。ディレクトリーが存在しない場合、作成されます。
```js
const dirName = "directoryToGetName";
// ディレクトリーハンドル 'currentDirHandle' があると仮定
const subDir = currentDirHandle.getDirectoryHandle(dirName, { create: true });
```
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- [File System Access API](/ja/docs/Web/API/File_System_Access_API)
- [The File System Access API: simplifying access to local files](https://web.dev/file-system-access/)