 |
- Author:
- mwarning (IP: 178.202.96.147)
- Timestamp:
- 10/26/10 10:22:55 (3 years ago)
- Comment:
Remove FileScan? as it is deprecated now.
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ChapterIoFileSystem
| v9 |
v10 |
|
| 66 | 66 | {{{ |
|---|
| 67 | 67 | #!d |
|---|
| 68 | | path.toList (void delegate (char[] parent, char[] name, bool isDir) dg); |
|---|
| 69 | | }}} |
|---|
| 70 | | |
|---|
| 71 | | This version of toList() can be used to construct custom file ''visitors'', and is used for that purpose by the [#!FileScan] module. |
|---|
| | 68 | path.toList (bool delegate (FilePath path, bool isFolder) dg); |
|---|
| | 69 | }}} |
|---|
| | 70 | |
|---|
| | 71 | This version of toList() can be used to construct custom file ''visitors''. |
|---|
| 72 | 72 | |
|---|
| 73 | 73 | === !FilePath Exceptions === |
|---|
| 255 | 255 | IO exceptions will be throws where an underlying OS or file-system error occurs. |
|---|
| 256 | 256 | |
|---|
| 257 | | == !FileScan == |
|---|
| 258 | | |
|---|
| 259 | | The !FileScan module wraps functionality from !FilePath.toList to provide something more concrete. The principal distinction is that !FileScan recurses folder-trees, and generates a list of both files and the folders containing them. |
|---|
| 260 | | |
|---|
| 261 | | To generate a list of D files, and the folders where they reside, try this: |
|---|
| 262 | | {{{ |
|---|
| 263 | | #!d |
|---|
| 264 | | import tango.io.FileScan; |
|---|
| 265 | | |
|---|
| 266 | | auto scan = new FileScan; |
|---|
| 267 | | scan (new FilePath("."), ".d"); |
|---|
| 268 | | |
|---|
| 269 | | foreach (folder; scan.folders) |
|---|
| 270 | | Cout (folder).newline; |
|---|
| 271 | | |
|---|
| 272 | | foreach (file; scan.files) |
|---|
| 273 | | Cout (file).newline; |
|---|
| 274 | | }}} |
|---|
| 275 | | |
|---|
| 276 | | This example executes a sweep across all files ending with ".d", beginning at the current directory, and extending across all sub-directories. Each folder containing a located file is displayed on the console, followed by a list of the located file names. |
|---|
| 277 | | |
|---|
| 278 | | !FileScan has a number of ways to override the simplistic file filtering illustrated above, using a delegate: |
|---|
| 279 | | {{{ |
|---|
| 280 | | #!d |
|---|
| 281 | | bool delegate (FilePath path, bool isDir) |
|---|
| 282 | | }}} |
|---|
| 283 | | |
|---|
| 284 | | The return value of the delegate should be true to add the instance, or false to ignore it. Argument isDir indicated whether the or not the instance is a folder or a file. |
|---|
| 285 | | |
|---|
| 286 | | === !FileScan Exceptions === |
|---|
| 287 | | |
|---|
| 288 | | No explicit exceptions are thrown, but those from !FilePath.toList will be exposed to the caller – generally file-system failures reported by the underlying OS. |
|---|
| 289 | | |
|---|
| 290 | | |
|---|
| 291 | | |
|---|
| 292 | | |
|---|
| | 257 | |
|---|
| | 258 | |
|---|
| | 259 | |
|---|
| | 260 | |
|
 |
 |
|
 |
Copyright © 2006-2013 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic