From 51c0e1afa711c8506296484796aa3b81b0cfd1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Wed, 8 Mar 2023 18:50:43 +0800 Subject: [PATCH] =?UTF-8?q?enhance(file):=E4=BF=AE=E6=AD=A3=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=96=87=E4=BB=B6=E6=97=B6=E7=9A=84=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands/files.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/commands/files.rs b/src-tauri/src/commands/files.rs index 8a40a59..84e50e0 100644 --- a/src-tauri/src/commands/files.rs +++ b/src-tauri/src/commands/files.rs @@ -10,7 +10,7 @@ pub struct FileItem { #[tauri::command] pub fn scan_directory(target: String) -> Result, String> { - WalkDir::new(target) + let mut file_items = WalkDir::new(target) .into_iter() .filter_map(|f| f.ok()) .filter(|f| f.path().is_file()) @@ -32,5 +32,8 @@ pub fn scan_directory(target: String) -> Result, String> { }) }) .collect::, anyhow::Error>>() - .map_err(|e| e.to_string()) + .map_err(|e| e.to_string())?; + file_items.sort_by(|a, b| a.filename.partial_cmp(&b.filename).unwrap()); + + Ok(file_items) }