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 /** | 5 /** |
6 * [Directory] objects are used for working with directories. | 6 * [Directory] objects are used for working with directories. |
7 */ | 7 */ |
8 interface Directory default _Directory { | 8 interface Directory default _Directory { |
9 /** | 9 /** |
10 * Creates a directory object. The path is either a full path or | 10 * Creates a directory object. The path is either a full path or |
11 * relative to the directory in which the Dart VM was | 11 * relative to the directory in which the Dart VM was |
12 * started. | 12 * started. |
13 */ | 13 */ |
14 Directory(String path); | 14 Directory(String path); |
15 | 15 |
16 /** | 16 /** |
17 * Check whether a directory with this name already exists. If the | 17 * Check whether a directory with this name already exists. If the |
18 * operation completes successfully the [existsHandler] is called with | 18 * operation completes successfully [onExists] is called with the |
19 * the result. Otherwise the [errorHandler] is called. | 19 * result. Otherwise [onError] is called. |
20 */ | 20 */ |
21 void exists(); | 21 void exists(); |
22 | 22 |
23 /** | 23 /** |
24 * Synchronously check whether a directory with this name already exists. | 24 * Synchronously check whether a directory with this name already exists. |
25 */ | 25 */ |
26 bool existsSync(); | 26 bool existsSync(); |
27 | 27 |
28 /** | 28 /** |
29 * Creates the directory with this name if it does not exist. | 29 * Creates the directory with this name if it does not exist. If |
30 * If the directory is successfully created the [createHandler] is | 30 * the directory is successfully created [onCreate] is |
31 * called. Otherwise the [errorHandler] is called. | 31 * called. Otherwise [onError] is called. |
32 */ | 32 */ |
33 void create(); | 33 void create(); |
34 | 34 |
35 /** | 35 /** |
36 * Synchronously creates the directory with this name if it does not exist. | 36 * Synchronously creates the directory with this name if it does not exist. |
37 * Throws an exception if the directory already exists. | 37 * Throws an exception if the directory already exists. |
38 */ | 38 */ |
39 void createSync(); | 39 void createSync(); |
40 | 40 |
41 /** | 41 /** |
42 * Creates a temporary directory with a name based on the current path. | 42 * Creates a temporary directory with a name based on the current path. |
43 * This name and path is used as a template, and additional characters are | 43 * This name and path is used as a template, and additional characters are |
44 * appended to it by the call to make a unique directory name. If the | 44 * appended to it by the call to make a unique directory name. If the |
45 * path is the empty string, a default system temp directory and name | 45 * path is the empty string, a default system temp directory and name |
46 * are used for the template. | 46 * are used for the template. |
47 * The path is modified to be the path of the new directory. | 47 * The path is modified to be the path of the new directory. |
48 * After the new directory is created, and the path modified, the callback | 48 * After the new directory is created, and the path modified, the callback |
49 * createTempHandler will be called. The error handler is called if | 49 * [onCreateTemp] will be called. The error handler is called if |
50 * the temporary directory cannot be created. | 50 * the temporary directory cannot be created. |
51 */ | 51 */ |
52 void createTemp(); | 52 void createTemp(); |
53 | 53 |
54 /** | 54 /** |
55 * Synchronously creates a temporary directory with a name based on the | 55 * Synchronously creates a temporary directory with a name based on the |
56 * current path. This name and path is used as a template, and additional | 56 * current path. This name and path is used as a template, and additional |
57 * characters are appended to it by the call to make a unique directory name. | 57 * characters are appended to it by the call to make a unique directory name. |
58 * If the path is the empty string, a default system temp directory and name | 58 * If the path is the empty string, a default system temp directory and name |
59 * are used for the template. | 59 * are used for the template. |
60 * The path is modified to be the path of the new directory. | 60 * The path is modified to be the path of the new directory. |
61 */ | 61 */ |
62 void createTempSync(); | 62 void createTempSync(); |
63 | 63 |
64 /** | 64 /** |
65 * Deletes the directory with this name. If the operation completes | 65 * Deletes the directory with this name. If the operation completes |
66 * successfully the [deleteHandler] is called. Otherwise the | 66 * successfully [onDelete] is called. Otherwise [onError] is called. |
67 * [errorHandler] is called. | |
68 * | 67 * |
69 * If [recursive] is [:true:] this directory and all sub-directories | 68 * If [recursive] is [:true:] this directory and all sub-directories |
70 * and files in the directory are deleted. If [recursive] is | 69 * and files in the directory are deleted. If [recursive] is |
71 * [:false:] only this directory (which must be empty) is | 70 * [:false:] only this directory (which must be empty) is |
72 * deleted. [recursive] is [:false:] by default. | 71 * deleted. [recursive] is [:false:] by default. |
73 */ | 72 */ |
74 void delete([bool recursive]); | 73 void delete([bool recursive]); |
75 | 74 |
76 /** | 75 /** |
77 * Deletes the directory with this name. Throws an exception | 76 * Deletes the directory with this name. Throws an exception |
(...skipping 14 matching lines...) Expand all Loading... | |
92 * the listing operation is recursive, the error handler is called | 91 * the listing operation is recursive, the error handler is called |
93 * if a subdirectory cannot be opened for listing. | 92 * if a subdirectory cannot be opened for listing. |
94 */ | 93 */ |
95 void list([bool recursive]); | 94 void list([bool recursive]); |
96 | 95 |
97 /** | 96 /** |
98 * Sets the directory handler that is called for all directories | 97 * Sets the directory handler that is called for all directories |
99 * during listing operations. The directory handler is called with | 98 * during listing operations. The directory handler is called with |
100 * the full path of the directory. | 99 * the full path of the directory. |
101 */ | 100 */ |
102 void set dirHandler(void dirHandler(String dir)); | 101 void set onDir(void onDir(String dir)); |
103 | 102 |
104 /** | 103 /** |
105 * Sets the handler that is called for all files during listing | 104 * Sets the handler that is called for all files during listing |
106 * operations. The file handler is called with the full path of the | 105 * operations. The file handler is called with the full path of the |
107 * file. | 106 * file. |
108 */ | 107 */ |
109 void set fileHandler(void fileHandler(String file)); | 108 void set onFile(void onFile(String file)); |
110 | 109 |
111 /** | 110 /** |
112 * Set the handler that is called when a directory listing is | 111 * Set the handler that is called when a directory listing is |
113 * done. The handler is called with an indication of whether or not | 112 * done. The handler is called with an indication of whether or not |
114 * the listing operation completed. | 113 * the listing operation completed. |
115 */ | 114 */ |
116 void set doneHandler(void doneHandler(bool completed)); | 115 void set onDone(void onDone(bool completed)); |
117 | 116 |
118 /** | 117 /** |
119 * Set the handler that is called when checking if a directory with this | 118 * Set the handler that is called when checking if a directory with this |
120 * name exists. | 119 * name exists. |
121 */ | 120 */ |
122 void set existsHandler(void existsHandler(bool exists)); | 121 void set onExists(void onExists(bool exists)); |
123 | 122 |
124 /** | 123 /** |
125 * Set the handler that is called when a directory is successfully created. | 124 * Set the handler that is called when a directory is successfully created. |
126 */ | 125 */ |
127 void set createHandler(void createHandler()); | 126 void set onCreate(void onCreate()); |
Søren Gjesse
2012/02/29 07:41:24
Wondering whether this should be onCreated instead
| |
128 | 127 |
129 /** | 128 /** |
130 * Set the handler that is called when a temporary directory is | 129 * Set the handler that is called when a temporary directory is |
131 * successfully created. | 130 * successfully created. |
132 */ | 131 */ |
133 void set createTempHandler(void createTempHandler()); | 132 void set onCreateTemp(void onCreateTemp()); |
Søren Gjesse
2012/02/29 07:41:24
Same here onTempCreated?
| |
134 | 133 |
135 /** | 134 /** |
136 * Set the handler that is called when a directory is successfully | 135 * Set the handler that is called when a directory is successfully |
137 * deleted. | 136 * deleted. |
138 */ | 137 */ |
139 void set deleteHandler(void deleteHandler()); | 138 void set onDelete(void onDelete()); |
Søren Gjesse
2012/02/29 07:41:24
onDeleted?
| |
140 | 139 |
141 /** | 140 /** |
142 * Sets the handler that is called if there is an error while listing | 141 * Sets the handler that is called if there is an error while listing |
143 * or creating directories. | 142 * or creating directories. |
144 */ | 143 */ |
145 void set errorHandler(void errorHandler(String error)); | 144 void set onError(void onError(String error)); |
146 | 145 |
147 /** | 146 /** |
148 * Gets the path of this directory. | 147 * Gets the path of this directory. |
149 */ | 148 */ |
150 final String path; | 149 final String path; |
151 } | 150 } |
152 | 151 |
153 | 152 |
154 class DirectoryException { | 153 class DirectoryException { |
155 const DirectoryException([String this.message, int this.errorCode = 0]); | 154 const DirectoryException([String this.message, int this.errorCode = 0]); |
156 String toString() => "DirectoryException: $message"; | 155 String toString() => "DirectoryException: $message"; |
157 final String message; | 156 final String message; |
158 final int errorCode; | 157 final int errorCode; |
159 } | 158 } |
OLD | NEW |