feat(file):增加修改文件名称的功能。

This commit is contained in:
徐涛
2023-03-23 09:52:26 +08:00
parent 65943e33b9
commit 0eb69d777d
4 changed files with 77 additions and 6 deletions

View File

@@ -1,4 +1,7 @@
use std::{fs::DirEntry, path::Path};
use std::{
fs::{self, DirEntry},
path::{Path, PathBuf},
};
use mountpoints::mountinfos;
use serde::Serialize;
@@ -193,3 +196,17 @@ pub async fn scan_for_child_dirs<R: Runtime>(
child_dirs.sort_by(|a, b| a.dirname.partial_cmp(&b.dirname).unwrap());
Ok(child_dirs)
}
#[tauri::command]
pub async fn rename_file<R: Runtime>(
_app: tauri::AppHandle<R>,
_window: tauri::Window<R>,
store_path: String,
origin_name: String,
new_name: String,
) -> Result<(), String> {
let origin_file = PathBuf::from(store_path.clone()).join(origin_name);
let new_file = PathBuf::from(store_path).join(new_name);
fs::rename(origin_file, new_file).map_err(|e| format!("重命名问文件失败,{}", e))?;
Ok(())
}

View File

@@ -15,7 +15,8 @@ fn main() {
.invoke_handler(tauri::generate_handler![
commands::prelude::scan_directory,
commands::prelude::show_drives,
commands::prelude::scan_for_child_dirs
commands::prelude::scan_for_child_dirs,
commands::prelude::rename_file
])
.setup(|app| {
let main_window = app.get_window("main").unwrap();