List files in a directory. Returns a sorted list of entries as `(filename, is_directory)` tuples. # Errors Returns an error if the path is not a directory or cannot be read.
(&self, path: &str)
| 20 | /// |
| 21 | /// Returns an error if the path is not a directory or cannot be read. |
| 22 | pub fn list_dir(&self, path: &str) -> io::Result<Vec<(String, bool)>> { |
| 23 | let abs_path = self.resolve_path(path)?; |
| 24 | let mut entries = Vec::new(); |
| 25 | |
| 26 | for entry in fs::read_dir(&abs_path)? { |
| 27 | let entry = entry?; |
| 28 | let file_name = entry.file_name().to_string_lossy().to_string(); |
| 29 | let file_type = entry.file_type()?; |
| 30 | entries.push((file_name, file_type.is_dir())); |
| 31 | } |
| 32 | |
| 33 | // Sort for consistent ordering |
| 34 | entries.sort_by(|a, b| a.0.cmp(&b.0)); |
| 35 | Ok(entries) |
| 36 | } |
| 37 | |
| 38 | /// Walk the directory tree recursively. |
| 39 | /// |