gitbutler/src-tauri/src/fs.rs

20 lines
584 B
Rust
Raw Normal View History

use std::path::Path;
2023-02-07 12:06:44 +03:00
use walkdir::WalkDir;
// Returns an ordered list of relative paths for files inside a directory recursively.
pub fn list_files(dir_path: &Path) -> Result<Vec<String>, std::io::Error> {
let mut files = vec![];
for entry in WalkDir::new(dir_path) {
let entry = entry?;
if entry.file_type().is_file() {
2023-02-07 12:06:44 +03:00
let path = entry.path();
let path = path.strip_prefix(dir_path).unwrap();
let path = path.to_str().unwrap().to_string();
files.push(path);
2023-02-07 12:06:44 +03:00
}
}
files.sort();
2023-02-07 17:44:02 +03:00
Ok(files)
2023-02-07 12:06:44 +03:00
}