OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** Abstraction for file systems and utility functions to manipulate paths. */ | 5 /** Abstraction for file systems and utility functions to manipulate paths. */ |
6 #library('file_system'); | 6 #library('file_system'); |
7 | 7 |
8 /** | 8 /** |
9 * Abstraction around file system access to work in a variety of different | 9 * Abstraction around file system access to work in a variety of different |
10 * environments. | 10 * environments. |
11 */ | 11 */ |
12 interface FileSystem { | 12 interface FileSystem { |
13 String readAll(String filename); | 13 String readAll(String filename); |
14 | 14 |
15 void writeString(String outfile, String text); | 15 void writeString(String outfile, String text); |
16 | 16 |
17 bool fileExists(String filename); | 17 bool fileExists(String filename); |
| 18 |
| 19 void createDirectory(String path, [bool recursive]); |
| 20 void removeDirectory(String path, [bool recursive]); |
18 } | 21 } |
19 | 22 |
20 /** Join [path1] to [path2]. */ | 23 /** Join [path1] to [path2]. */ |
21 String joinPaths(String path1, String path2) { | 24 String joinPaths(String path1, String path2) { |
22 var pieces = path1.split('/'); | 25 var pieces = path1.split('/'); |
23 for (var piece in path2.split('/')) { | 26 for (var piece in path2.split('/')) { |
24 if (piece == '..' && pieces.length > 0 && pieces.last() != '.' | 27 if (piece == '..' && pieces.length > 0 && pieces.last() != '.' |
25 && pieces.last() != '..') { | 28 && pieces.last() != '..') { |
26 pieces.removeLast(); | 29 pieces.removeLast(); |
27 } else if (piece != '') { | 30 } else if (piece != '') { |
(...skipping 18 matching lines...) Expand all Loading... |
46 | 49 |
47 /** Returns the file name without directory for the [path]. */ | 50 /** Returns the file name without directory for the [path]. */ |
48 String basename(String path) { | 51 String basename(String path) { |
49 int lastSlash = path.lastIndexOf('/', path.length); | 52 int lastSlash = path.lastIndexOf('/', path.length); |
50 if (lastSlash == -1) { | 53 if (lastSlash == -1) { |
51 return path; | 54 return path; |
52 } else { | 55 } else { |
53 return path.substring(lastSlash + 1); | 56 return path.substring(lastSlash + 1); |
54 } | 57 } |
55 } | 58 } |
OLD | NEW |