| 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 /** Abstraction for file systems and utility functions to manipulate paths. */ | 5 /** |
| 6 #library('file_system'); | 6 * TODO(johnniwinther): Path manipulation copied from frog/file_system.dart. |
| 7 * Should be converted to use Path from dart:io when this is completed. |
| 8 */ |
| 9 #library('file_util'); |
| 7 | 10 |
| 8 /** | 11 /** |
| 9 * Abstraction around file system access to work in a variety of different | 12 * Replaces all back slashes (\) with forward slashes (/) in [path] and |
| 10 * environments. | |
| 11 */ | |
| 12 interface FileSystem { | |
| 13 String readAll(String filename); | |
| 14 | |
| 15 void writeString(String outfile, String text); | |
| 16 | |
| 17 bool fileExists(String filename); | |
| 18 | |
| 19 void createDirectory(String path, [bool recursive]); | |
| 20 void removeDirectory(String path, [bool recursive]); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * Replaces all back slashes (\) with forward slashes (/) in [path] and | |
| 25 * return the result. | 13 * return the result. |
| 26 */ | 14 */ |
| 27 String canonicalizePath(String path) { | 15 String canonicalizePath(String path) { |
| 28 return path.replaceAll('\\', '/'); | 16 return path.replaceAll('\\', '/'); |
| 29 } | 17 } |
| 30 | 18 |
| 31 /** Join [path1] to [path2]. */ | 19 /** Join [path1] to [path2]. */ |
| 32 String joinPaths(String path1, String path2) { | 20 String joinPaths(String path1, String path2) { |
| 33 path1 = canonicalizePath(path1); | 21 path1 = canonicalizePath(path1); |
| 34 path2 = canonicalizePath(path2); | 22 path2 = canonicalizePath(path2); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 64 String basename(String path) { | 52 String basename(String path) { |
| 65 path = canonicalizePath(path); | 53 path = canonicalizePath(path); |
| 66 | 54 |
| 67 int lastSlash = path.lastIndexOf('/', path.length); | 55 int lastSlash = path.lastIndexOf('/', path.length); |
| 68 if (lastSlash == -1) { | 56 if (lastSlash == -1) { |
| 69 return path; | 57 return path; |
| 70 } else { | 58 } else { |
| 71 return path.substring(lastSlash + 1); | 59 return path.substring(lastSlash + 1); |
| 72 } | 60 } |
| 73 } | 61 } |
| OLD | NEW |