diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-04-21 15:45:51 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-04-21 15:45:51 -0700 |
| commit | 8688b1b845f3ceede2a62da6a2fc2256e6bcfd2a (patch) | |
| tree | b65dbd7afc908a38765e520d5270f19c05c6c237 /src | |
| parent | 7235f3cee2fd7ceaf697232cd2a2c3b9ceba50ba (diff) | |
| download | rust-8688b1b845f3ceede2a62da6a2fc2256e6bcfd2a.tar.gz rust-8688b1b845f3ceede2a62da6a2fc2256e6bcfd2a.zip | |
core: Add os::walk_dir
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/os.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 269744296f8..9af5f1f6560 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -34,6 +34,7 @@ export homedir, list_dir, list_dir_path, path_is_dir, path_exists, copy_file; export last_os_error; export set_exit_status; +export walk_dir; // FIXME: move these to str perhaps? export as_c_charp, fill_charp_buf; @@ -387,7 +388,34 @@ fn homedir() -> option<path> { } } +#[doc = "Recursively walk a directory structure"] +fn walk_dir(p: path, f: fn(path) -> bool) { + walk_dir_(p, f); + + fn walk_dir_(p: path, f: fn(path) -> bool) -> bool { + let mut keepgoing = true; + list_dir(p).each {|q| + let path = path::connect(p, q); + if !f(path) { + keepgoing = false; + false + } else { + if path_is_dir(path) { + if !walk_dir_(path, f) { + keepgoing = false; + false + } else { + true + } + } else { + true + } + } + } + ret keepgoing; + } +} #[doc = "Indicates whether a path represents a directory"] fn path_is_dir(p: path) -> bool { |
