| 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 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
| 7 */ | 7 */ |
| 8 #library('pub_io'); | 8 #library('pub_io'); |
| 9 | 9 |
| 10 #import('dart:io'); | 10 #import('dart:io'); |
| 11 | 11 |
| 12 #import('../lib/file_system.dart', prefix: 'fs'); | |
| 13 | |
| 14 /** Gets the current working directory. */ | 12 /** Gets the current working directory. */ |
| 15 String get workingDir() => new File('.').fullPathSync(); | 13 String get workingDir() => new File('.').fullPathSync(); |
| 16 | 14 |
| 17 /** | 15 /** |
| 18 * Joins a number of path string parts into a single path. Handles | 16 * Joins a number of path string parts into a single path. Handles |
| 19 * platform-specific path separators. Parts can be [String], [Directory], or | 17 * platform-specific path separators. Parts can be [String], [Directory], or |
| 20 * [File] objects. | 18 * [File] objects. |
| 21 */ | 19 */ |
| 22 String join(part1, [part2, part3, part4]) { | 20 String join(part1, [part2, part3, part4]) { |
| 23 final parts = _getPath(part1).split('/'); | 21 final parts = _getPath(part1).split('/'); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 } | 36 } |
| 39 } | 37 } |
| 40 | 38 |
| 41 return Strings.join(parts, Platform.pathSeparator()); | 39 return Strings.join(parts, Platform.pathSeparator()); |
| 42 } | 40 } |
| 43 | 41 |
| 44 /** | 42 /** |
| 45 * Gets the basename, the file name without any leading directory path, for | 43 * Gets the basename, the file name without any leading directory path, for |
| 46 * [file], which can either be a [String], [File], or [Directory]. | 44 * [file], which can either be a [String], [File], or [Directory]. |
| 47 */ | 45 */ |
| 46 // TODO(rnystrom): Copied from file_system (so that we don't have to add |
| 47 // file_system to the SDK). Should unify. |
| 48 String basename(file) { | 48 String basename(file) { |
| 49 return fs.basename(_getPath(file)); | 49 file = _getPath(file).replaceAll('\\', '/'); |
| 50 |
| 51 int lastSlash = file.lastIndexOf('/', file.length); |
| 52 if (lastSlash == -1) { |
| 53 return file; |
| 54 } else { |
| 55 return file.substring(lastSlash + 1); |
| 56 } |
| 50 } | 57 } |
| 51 | 58 |
| 52 /** | 59 /** |
| 53 * Asynchronously determines if [file], which can be a [String] file path or a | 60 * Asynchronously determines if [file], which can be a [String] file path or a |
| 54 * [File], exists on the file system. Returns a [Future] that completes with | 61 * [File], exists on the file system. Returns a [Future] that completes with |
| 55 * the result. | 62 * the result. |
| 56 */ | 63 */ |
| 57 Future<bool> fileExists(file) { | 64 Future<bool> fileExists(file) { |
| 58 final completer = new Completer<bool>(); | 65 final completer = new Completer<bool>(); |
| 59 | 66 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 325 } |
| 319 | 326 |
| 320 /** | 327 /** |
| 321 * Gets a [Directory] for [entry], which can either already be one, or be a | 328 * Gets a [Directory] for [entry], which can either already be one, or be a |
| 322 * [String]. | 329 * [String]. |
| 323 */ | 330 */ |
| 324 Directory _getDirectory(entry) { | 331 Directory _getDirectory(entry) { |
| 325 if (entry is Directory) return entry; | 332 if (entry is Directory) return entry; |
| 326 return new Directory(entry); | 333 return new Directory(entry); |
| 327 } | 334 } |
| OLD | NEW |