Function std::io::fs::readdirExperimental
[-]
[+]
[src]
pub fn readdir(path: &Path) -> IoResult<Vec<Path>>
Retrieve a vector containing all entries within a provided directory
Example
fn main() { use std::io::fs::PathExtensions; use std::io::fs; use std::io; // one possible implementation of fs::walk_dir only visiting files fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> { if dir.is_dir() { let contents = try!(fs::readdir(dir)); for entry in contents.iter() { if entry.is_dir() { try!(visit_dirs(entry, |p| cb(p))); } else { cb(entry); } } Ok(()) } else { Err(io::standard_error(io::InvalidInput)) } } }use std::io::fs::PathExtensions; use std::io::fs; use std::io; // one possible implementation of fs::walk_dir only visiting files fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> { if dir.is_dir() { let contents = try!(fs::readdir(dir)); for entry in contents.iter() { if entry.is_dir() { try!(visit_dirs(entry, |p| cb(p))); } else { cb(entry); } } Ok(()) } else { Err(io::standard_error(io::InvalidInput)) } }
Error
This function will return an error if the provided path
doesn't exist, if
the process lacks permissions to view the contents or if the path
points
at a non-directory file