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 /** |
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 * | 9 * |
10 * A Directory instance is an object holding a [path] on which operations can | 10 * A Directory instance is an object holding a [path] on which operations can |
(...skipping 26 matching lines...) Expand all Loading... |
37 * import 'dart:io'; | 37 * import 'dart:io'; |
38 * | 38 * |
39 * void main() { | 39 * void main() { |
40 * // Creates dir/ and dir/subdir/. | 40 * // Creates dir/ and dir/subdir/. |
41 * new Directory('dir/subdir').create(recursive: true) | 41 * new Directory('dir/subdir').create(recursive: true) |
42 * // The created directory is returned as a Future. | 42 * // The created directory is returned as a Future. |
43 * .then((Directory directory) { | 43 * .then((Directory directory) { |
44 * print(directory.path); | 44 * print(directory.path); |
45 * }); | 45 * }); |
46 * } | 46 * } |
47 * | 47 * |
48 * ## List a directory | 48 * ## List a directory |
49 * | 49 * |
50 * Use the [list] or [listSync] methods to get the files and directories | 50 * Use the [list] or [listSync] methods to get the files and directories |
51 * contained by a directory. | 51 * contained by a directory. |
52 * Set `recursive` to true to recursively list all subdirectories. | 52 * Set `recursive` to true to recursively list all subdirectories. |
53 * Set `followLinks` to true to follow symbolic links. | 53 * Set `followLinks` to true to follow symbolic links. |
54 * The list method returns a [Stream] that provides FileSystemEntity | 54 * The list method returns a [Stream] that provides FileSystemEntity |
55 * objects. Use the listen callback function to process each object | 55 * objects. Use the listen callback function to process each object |
56 * as it become available. | 56 * as it become available. |
57 * | 57 * |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 * }); | 93 * }); |
94 * } | 94 * } |
95 * | 95 * |
96 * | 96 * |
97 * In addition to exists, the [stat], [rename], and | 97 * In addition to exists, the [stat], [rename], and |
98 * other methods, return Futures. | 98 * other methods, return Futures. |
99 * | 99 * |
100 * ## Other resources | 100 * ## Other resources |
101 * | 101 * |
102 * * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directori
es-and-symlinks) | 102 * * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directori
es-and-symlinks) |
103 * provides additional task-oriented code samples that show how to use | 103 * provides additional task-oriented code samples that show how to use |
104 * various API from the Directory class and the related [File] class. | 104 * various API from the Directory class and the related [File] class. |
105 * | 105 * |
106 * * [I/O for Command-Line Apps](https://www.dartlang.org/docs/dart-up-and-runni
ng/contents/ch03.html#ch03-dartio---file-and-socket-io-for-command-line-apps) | 106 * * [I/O for Command-Line Apps](https://www.dartlang.org/docs/dart-up-and-runni
ng/contents/ch03.html#ch03-dartio---file-and-socket-io-for-command-line-apps) |
107 * a section from _A Tour of the Dart Libraries_ | 107 * a section from _A Tour of the Dart Libraries_ |
108 * covers files and directories. | 108 * covers files and directories. |
109 * | 109 * |
110 * * [Write Command-Line Apps](https://www.dartlang.org/docs/tutorials/cmdline/)
, | 110 * * [Write Command-Line Apps](https://www.dartlang.org/docs/tutorials/cmdline/)
, |
111 * a tutorial about writing command-line apps, includes information | 111 * a tutorial about writing command-line apps, includes information |
112 * about files and directories. | 112 * about files and directories. |
113 */ | 113 */ |
114 abstract class Directory extends FileSystemEntity { | 114 abstract class Directory implements FileSystemEntity { |
115 /** | 115 /** |
116 * Gets the path of this directory. | 116 * Gets the path of this directory. |
117 */ | 117 */ |
118 final String path; | 118 final String path; |
119 | 119 |
120 /** | 120 /** |
121 * Creates a [Directory] object. | 121 * Creates a [Directory] object. |
122 * | 122 * |
123 * If [path] is a relative path, it will be interpreted relative to the | 123 * If [path] is a relative path, it will be interpreted relative to the |
124 * current working directory (see [Directory.current]), when used. | 124 * current working directory (see [Directory.current]), when used. |
(...skipping 10 matching lines...) Expand all Loading... |
135 */ | 135 */ |
136 factory Directory.fromUri(Uri uri) => new Directory(uri.toFilePath()); | 136 factory Directory.fromUri(Uri uri) => new Directory(uri.toFilePath()); |
137 | 137 |
138 /** | 138 /** |
139 * Creates a directory object pointing to the current working | 139 * Creates a directory object pointing to the current working |
140 * directory. | 140 * directory. |
141 */ | 141 */ |
142 static Directory get current => _Directory.current; | 142 static Directory get current => _Directory.current; |
143 | 143 |
144 /** | 144 /** |
| 145 * Returns a [Uri] representing the directory's location. |
| 146 * |
| 147 * The returned URI's scheme is always "file" if the entity's [path] is |
| 148 * absolute, otherwise the scheme will be empty. |
| 149 * The returned URI's path always ends in a slash ('/'). |
| 150 */ |
| 151 Uri get uri; |
| 152 |
| 153 /** |
145 * Sets the current working directory of the Dart process including | 154 * Sets the current working directory of the Dart process including |
146 * all running isolates. The new value set can be either a [Directory] | 155 * all running isolates. The new value set can be either a [Directory] |
147 * or a [String]. | 156 * or a [String]. |
148 * | 157 * |
149 * The new value is passed to the OS's system call unchanged, so a | 158 * The new value is passed to the OS's system call unchanged, so a |
150 * relative path passed as the new working directory will be | 159 * relative path passed as the new working directory will be |
151 * resolved by the OS. | 160 * resolved by the OS. |
152 * | 161 * |
153 * Note that setting the current working directory is a synchronous | 162 * Note that setting the current working directory is a synchronous |
154 * operation and that it changes the the working directory of *all* | 163 * operation and that it changes the the working directory of *all* |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 * directories, files, and links. | 304 * directories, files, and links. |
296 */ | 305 */ |
297 List<FileSystemEntity> listSync({bool recursive: false, | 306 List<FileSystemEntity> listSync({bool recursive: false, |
298 bool followLinks: true}); | 307 bool followLinks: true}); |
299 | 308 |
300 /** | 309 /** |
301 * Returns a human readable string for this Directory instance. | 310 * Returns a human readable string for this Directory instance. |
302 */ | 311 */ |
303 String toString(); | 312 String toString(); |
304 } | 313 } |
OLD | NEW |