OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
Søren Gjesse
2014/02/12 13:16:35
We should have a section on the fact that Director
mem
2014/02/12 19:17:07
Done.
| |
8 * A reference to a directory (or _folder_) on the file system. | 8 * A reference to a directory (or _folder_) on the file system. |
9 * | |
10 * A [Directory] has a [path] (the pathname to the directory) and a [parent] | |
Søren Gjesse
2014/02/12 13:16:35
We should merge this with the first line, and be p
mem
2014/02/12 19:17:07
The convention is to have a single one-liner that
| |
11 * (the directory that contains this directory). | |
12 * Create a new Directory object with a pathname to access the directory on | |
13 * the file system from your program. | |
14 * | |
15 * var myDir = new Directory('myDir'); | |
16 * | |
17 * Most methods in this class occur in synchronous and asynchronous pairs, | |
18 * for example, [create] and [createSync]. | |
19 * Unless you have a specific reason for using the synchronous version | |
20 * of a method, prefer the asynchronous version to avoid blocking your program. | |
21 * | |
22 * ## Create a directory | |
23 * | |
24 * The following code sample creates a directory using the [create] method. | |
25 * By setting the `recursive` parameter to true, you can create the | |
26 * named directory and all its necessary parent directories, | |
27 * if they do not already exist. | |
28 * | |
29 * import 'dart:io'; | |
30 * | |
31 * void main() { | |
32 * // Creates dir/ and dir/subdir/. | |
33 * new Directory('dir/subdir').create(recursive: true) | |
34 * // The created directory is returned as a Future. | |
35 * .then((Directory directory) { | |
36 * print(directory.path); | |
37 * }); | |
38 * } | |
39 * | |
40 * ## List a directory | |
41 * | |
42 * Use the [list] or [listSync] methods to get the files and directories | |
43 * contained by a directory. | |
44 * Set `recursive` to true to recursively list all subdirectories. | |
45 * Set `followLinks` to true to follow symbolic links. | |
46 * The list method returns a Stream that serves FileSystemEntity | |
Søren Gjesse
2014/02/12 13:16:35
serves -> provides
(serves is OK, but I think pro
mem
2014/02/12 19:17:07
Done.
| |
47 * objects. | |
48 * | |
49 * import 'dart:io'; | |
50 * | |
51 * void main() { | |
52 * // Get the system temp directory. | |
53 * var systemTempDir = Directory.systemTemp; | |
54 * | |
55 * // List directory contents, recursing into sub-directories, | |
56 * // but not following symbolic links. | |
57 * systemTempDir.list(recursive: true, followLinks: false) | |
58 * .listen((FileSystemEntity entity) { | |
59 * print(entity.path); | |
60 * }); | |
61 * } | |
62 * | |
63 * ## The use of Futures | |
64 * | |
65 * To avoid unintentional blocking of the program, | |
Søren Gjesse
2014/02/12 13:16:35
Maybe we should rephrase this somehow, e.g.
Whene
mem
2014/02/12 19:17:07
Done.
| |
66 * several methods use a [Future] to return a value. For example, | |
67 * the [exists] method, which determines whether the directory exists, | |
68 * returns a boolean value using a Future. | |
69 * Use `then` to register a callback function, which is called when | |
70 * the value is ready. | |
71 * | |
72 * import 'dart:io'; | |
73 * | |
74 * main() { | |
75 * final myDir = new Directory('dir'); | |
76 * myDir.exists().then((isThere) { | |
77 * isThere ? print('exists') : print('non-existent'); | |
78 * }); | |
79 * } | |
80 * | |
81 * | |
82 * In addition to exists, the [stat], [rename], and | |
83 * other methods, return Futures. | |
84 * | |
85 * ## Other resources | |
86 * | |
87 * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directories -and-symlinks) | |
88 * provides additional task-oriented code samples that show how to use | |
89 * various API from the Directory class and the related [File] class. | |
90 * | |
9 */ | 91 */ |
10 abstract class Directory implements FileSystemEntity { | 92 abstract class Directory implements FileSystemEntity { |
11 /** | 93 /** |
12 * Gets the path of this directory. | 94 * Gets the path of this directory. |
13 */ | 95 */ |
14 final String path; | 96 final String path; |
15 | 97 |
16 /** | 98 /** |
17 * Creates a directory object. The path is either an absolute path, | 99 * Creates a directory object. The path is either an absolute path, |
18 * or it is a relative path which is interpreted relative to the directory | 100 * or it is a relative path which is interpreted relative to the directory |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 * directories, files, and links. | 269 * directories, files, and links. |
188 */ | 270 */ |
189 List<FileSystemEntity> listSync({bool recursive: false, | 271 List<FileSystemEntity> listSync({bool recursive: false, |
190 bool followLinks: true}); | 272 bool followLinks: true}); |
191 | 273 |
192 /** | 274 /** |
193 * Returns a human readable string for this Directory instance. | 275 * Returns a human readable string for this Directory instance. |
194 */ | 276 */ |
195 String toString(); | 277 String toString(); |
196 } | 278 } |
OLD | NEW |