check page
This commit is contained in:
@@ -250,6 +250,96 @@ fn rename_videos(files: Vec<String>, prefix: String, base_name: String) -> Resul
|
||||
Ok(format!("Successfully renamed {} files.", renamed_count))
|
||||
}
|
||||
|
||||
// --- Check Logic ---
|
||||
|
||||
fn remove_empty_dirs_recursive(path: &Path, deleted_list: &mut Vec<String>) -> std::io::Result<()> {
|
||||
if path.is_dir() {
|
||||
let read_dir = fs::read_dir(path)?;
|
||||
for entry in read_dir {
|
||||
let entry = entry?;
|
||||
let child_path = entry.path();
|
||||
if child_path.is_dir() {
|
||||
remove_empty_dirs_recursive(&child_path, deleted_list)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-check if empty after processing children
|
||||
// Use read_dir again to check if it's empty now
|
||||
let mut is_empty = true;
|
||||
let read_dir_check = fs::read_dir(path)?;
|
||||
for _ in read_dir_check {
|
||||
is_empty = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if is_empty {
|
||||
fs::remove_dir(path)?;
|
||||
deleted_list.push(path.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn delete_empty_dirs(path: String) -> Result<Vec<String>, String> {
|
||||
let root_path = Path::new(&path);
|
||||
if !root_path.exists() || !root_path.is_dir() {
|
||||
return Err("Path is not a valid directory".to_string());
|
||||
}
|
||||
|
||||
let mut deleted = Vec::new();
|
||||
|
||||
// We cannot delete the root path itself even if empty, per logic usually expected in tools.
|
||||
// So we iterate children and call recursive function.
|
||||
let read_dir = fs::read_dir(root_path).map_err(|e| e.to_string())?;
|
||||
|
||||
for entry in read_dir {
|
||||
let entry = entry.map_err(|e| e.to_string())?;
|
||||
let child_path = entry.path();
|
||||
if child_path.is_dir() {
|
||||
remove_empty_dirs_recursive(&child_path, &mut deleted).map_err(|e| e.to_string())?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(deleted)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn check_file_naming(path: String, prefix: String) -> Result<Vec<String>, String> {
|
||||
let root_path = Path::new(&path);
|
||||
if !root_path.exists() || !root_path.is_dir() {
|
||||
return Err("Path is not a valid directory".to_string());
|
||||
}
|
||||
|
||||
let mut mismatches = Vec::new();
|
||||
let mut stack = vec![root_path.to_path_buf()];
|
||||
|
||||
while let Some(current_dir) = stack.pop() {
|
||||
let read_dir = fs::read_dir(¤t_dir).map_err(|e| e.to_string())?;
|
||||
|
||||
for entry in read_dir {
|
||||
let entry = entry.map_err(|e| e.to_string())?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
stack.push(path);
|
||||
} else {
|
||||
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
// Check against prefix
|
||||
// NOTE: Should we check hidden files? Assuming ignoring hidden files for now if starting with dot?
|
||||
// Or just check everything. Let's check everything visible.
|
||||
if !name.starts_with(".") {
|
||||
if !name.starts_with(&prefix) {
|
||||
mismatches.push(path.to_string_lossy().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(mismatches)
|
||||
}
|
||||
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
@@ -265,8 +355,10 @@ pub fn run() {
|
||||
save_history_item,
|
||||
remove_history_item,
|
||||
check_dir_exists,
|
||||
rename_videos
|
||||
rename_videos,
|
||||
delete_empty_dirs,
|
||||
check_file_naming
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user