feat(file):增加修改文件名称的功能。
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user