mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-08 22:08:47 +08:00
Add load m3t dir support
This commit is contained in:
@@ -139,6 +139,63 @@ pub fn collect_files(
|
||||
))
|
||||
}
|
||||
|
||||
/// Finds all files with specific extensions in the specified directory and its subdirectories.
|
||||
pub fn find_ext_files(path: &str, recursive: bool, exts: &[&str]) -> io::Result<Vec<String>> {
|
||||
let mut result = Vec::new();
|
||||
let dir_path = Path::new(&path);
|
||||
|
||||
if dir_path.is_dir() {
|
||||
for entry in fs::read_dir(dir_path)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if path.is_file()
|
||||
&& path.file_name().map_or(false, |file| {
|
||||
path.extension().map_or(true, |_| {
|
||||
let file = file.to_string_lossy().to_lowercase();
|
||||
for ext in exts {
|
||||
if file.ends_with(&format!(".{}", ext)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
})
|
||||
})
|
||||
{
|
||||
if let Some(path_str) = path.to_str() {
|
||||
result.push(path_str.to_string());
|
||||
}
|
||||
} else if recursive && path.is_dir() {
|
||||
if let Some(path_str) = path.to_str() {
|
||||
let mut sub_files = find_arc_files(&path_str.to_string(), recursive)?;
|
||||
result.append(&mut sub_files);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Collects files with specific extensions from the specified path, either as a directory or a single file.
|
||||
pub fn collect_ext_files(
|
||||
path: &str,
|
||||
recursive: bool,
|
||||
exts: &[&str],
|
||||
) -> io::Result<(Vec<String>, bool)> {
|
||||
let pa = Path::new(path);
|
||||
if pa.is_dir() {
|
||||
return Ok((find_ext_files(path, recursive, exts)?, true));
|
||||
}
|
||||
if pa.is_file() {
|
||||
return Ok((vec![path.to_string()], false));
|
||||
}
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
format!("Path {} is neither a file nor a directory", pa.display()),
|
||||
))
|
||||
}
|
||||
|
||||
/// Collects archive files from the specified path, either as a directory or a single file.
|
||||
pub fn collect_arc_files(path: &str, recursive: bool) -> io::Result<(Vec<String>, bool)> {
|
||||
let pa = Path::new(path);
|
||||
|
||||
Reference in New Issue
Block a user