Function std::io::fs::readdirUnstable
[-]
[+]
[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<F>(dir: &Path, cb: &mut F) -> io::IoResult<()> where F: FnMut(&Path), { if dir.is_dir() { let contents = try!(fs::readdir(dir)); for entry in contents.iter() { if entry.is_dir() { try!(visit_dirs(entry, cb)); } 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<F>(dir: &Path, cb: &mut F) -> io::IoResult<()> where F: FnMut(&Path), { if dir.is_dir() { let contents = try!(fs::readdir(dir)); for entry in contents.iter() { if entry.is_dir() { try!(visit_dirs(entry, cb)); } 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