OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * The type of an entity on the file system, such as a file, directory, or link. | 8 * The type of an entity on the file system, such as a file, directory, or link. |
9 * | 9 * |
10 * These constants are used by the [FileSystemEntity] class | 10 * These constants are used by the [FileSystemEntity] class |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 * Here's the exists method in action: | 191 * Here's the exists method in action: |
192 * | 192 * |
193 * entity.exists().then((isThere) { | 193 * entity.exists().then((isThere) { |
194 * isThere ? print('exists') : print('non-existent'); | 194 * isThere ? print('exists') : print('non-existent'); |
195 * }); | 195 * }); |
196 * | 196 * |
197 * | 197 * |
198 * ## Other resources | 198 * ## Other resources |
199 * | 199 * |
200 * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directories
-and-symlinks) | 200 * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directories
-and-symlinks) |
201 * provides additional task-oriented code samples that show how to use | 201 * provides additional task-oriented code samples that show how to use |
202 * various API from the [Directory] class and the [File] class, | 202 * various API from the [Directory] class and the [File] class, |
203 * both subclasses of FileSystemEntity. | 203 * both subclasses of FileSystemEntity. |
204 * | 204 * |
205 * * [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) | 205 * * [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) |
206 * a section from _A Tour of the Dart Libraries_ | 206 * a section from _A Tour of the Dart Libraries_ |
207 * covers files and directories. | 207 * covers files and directories. |
208 * | 208 * |
209 * * [Write Command-Line Apps](https://www.dartlang.org/docs/tutorials/cmdline/)
, | 209 * * [Write Command-Line Apps](https://www.dartlang.org/docs/tutorials/cmdline/)
, |
210 * a tutorial about writing command-line apps, includes information | 210 * a tutorial about writing command-line apps, includes information |
211 * about files and directories. | 211 * about files and directories. |
212 | 212 |
213 */ | 213 */ |
214 abstract class FileSystemEntity { | 214 abstract class FileSystemEntity { |
215 String get path; | 215 String get path; |
216 | 216 |
217 /** | 217 /** |
| 218 * Returns a [Uri] representing the file system entity's location. |
| 219 * |
| 220 * The returned URI's scheme is always "file" if the entity's [path] is |
| 221 * absolute, otherwise the scheme will be empty. |
| 222 */ |
| 223 Uri get uri => new Uri.file(path); |
| 224 |
| 225 /** |
218 * Checks whether the file system entity with this path exists. Returns | 226 * Checks whether the file system entity with this path exists. Returns |
219 * a [:Future<bool>:] that completes with the result. | 227 * a [:Future<bool>:] that completes with the result. |
220 * | 228 * |
221 * Since FileSystemEntity is abstract, every FileSystemEntity object | 229 * Since FileSystemEntity is abstract, every FileSystemEntity object |
222 * is actually an instance of one of the subclasses [File], | 230 * is actually an instance of one of the subclasses [File], |
223 * [Directory], and [Link]. Calling [exists] on an instance of one | 231 * [Directory], and [Link]. Calling [exists] on an instance of one |
224 * of these subclasses checks whether the object exists in the file | 232 * of these subclasses checks whether the object exists in the file |
225 * system object exists and is of the correct type (file, directory, | 233 * system object exists and is of the correct type (file, directory, |
226 * or link). To check whether a path points to an object on the | 234 * or link). To check whether a path points to an object on the |
227 * file system, regardless of the object's type, use the [type] | 235 * file system, regardless of the object's type, use the [type] |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 return buffer.toString(); | 832 return buffer.toString(); |
825 } | 833 } |
826 } | 834 } |
827 | 835 |
828 | 836 |
829 class _FileSystemWatcher { | 837 class _FileSystemWatcher { |
830 external static Stream<FileSystemEvent> _watch( | 838 external static Stream<FileSystemEvent> _watch( |
831 String path, int events, bool recursive); | 839 String path, int events, bool recursive); |
832 external static bool get isSupported; | 840 external static bool get isSupported; |
833 } | 841 } |
OLD | NEW |