Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Unified Diff: sdk/lib/io/directory.dart

Issue 159713011: class-level docs for several dart:io classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/io/file.dart » ('j') | sdk/lib/io/file.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/directory.dart
diff --git a/sdk/lib/io/directory.dart b/sdk/lib/io/directory.dart
index e1fb143c1789d3ace7c4eb4ec3c9bcae2bcfb177..8d7c1760921766c30742d20d5b1ea9a47fda2cc2 100644
--- a/sdk/lib/io/directory.dart
+++ b/sdk/lib/io/directory.dart
@@ -6,6 +6,88 @@ part of dart.io;
/**
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.
* A reference to a directory (or _folder_) on the file system.
+ *
+ * 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
+ * (the directory that contains this directory).
+ * Create a new Directory object with a pathname to access the directory on
+ * the file system from your program.
+ *
+ * var myDir = new Directory('myDir');
+ *
+ * Most methods in this class occur in synchronous and asynchronous pairs,
+ * for example, [create] and [createSync].
+ * Unless you have a specific reason for using the synchronous version
+ * of a method, prefer the asynchronous version to avoid blocking your program.
+ *
+ * ## Create a directory
+ *
+ * The following code sample creates a directory using the [create] method.
+ * By setting the `recursive` parameter to true, you can create the
+ * named directory and all its necessary parent directories,
+ * if they do not already exist.
+ *
+ * import 'dart:io';
+ *
+ * void main() {
+ * // Creates dir/ and dir/subdir/.
+ * new Directory('dir/subdir').create(recursive: true)
+ * // The created directory is returned as a Future.
+ * .then((Directory directory) {
+ * print(directory.path);
+ * });
+ * }
+ *
+ * ## List a directory
+ *
+ * Use the [list] or [listSync] methods to get the files and directories
+ * contained by a directory.
+ * Set `recursive` to true to recursively list all subdirectories.
+ * Set `followLinks` to true to follow symbolic links.
+ * 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.
+ * objects.
+ *
+ * import 'dart:io';
+ *
+ * void main() {
+ * // Get the system temp directory.
+ * var systemTempDir = Directory.systemTemp;
+ *
+ * // List directory contents, recursing into sub-directories,
+ * // but not following symbolic links.
+ * systemTempDir.list(recursive: true, followLinks: false)
+ * .listen((FileSystemEntity entity) {
+ * print(entity.path);
+ * });
+ * }
+ *
+ * ## The use of Futures
+ *
+ * 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.
+ * several methods use a [Future] to return a value. For example,
+ * the [exists] method, which determines whether the directory exists,
+ * returns a boolean value using a Future.
+ * Use `then` to register a callback function, which is called when
+ * the value is ready.
+ *
+ * import 'dart:io';
+ *
+ * main() {
+ * final myDir = new Directory('dir');
+ * myDir.exists().then((isThere) {
+ * isThere ? print('exists') : print('non-existent');
+ * });
+ * }
+ *
+ *
+ * In addition to exists, the [stat], [rename], and
+ * other methods, return Futures.
+ *
+ * ## Other resources
+ *
+ * [Dart by Example](https://www.dartlang.org/dart-by-example/#files-directories-and-symlinks)
+ * provides additional task-oriented code samples that show how to use
+ * various API from the Directory class and the related [File] class.
+ *
*/
abstract class Directory implements FileSystemEntity {
/**
« no previous file with comments | « no previous file | sdk/lib/io/file.dart » ('j') | sdk/lib/io/file.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698