File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use tauri_plugin_updater::UpdaterExt;
15
15
fn exists ( path : String ) -> bool {
16
16
std:: path:: Path :: new ( & path) . exists ( )
17
17
}
18
+
18
19
/// 读取文件夹中的文件列表
19
20
/// 如果文件夹不存在,返回空列表
20
21
#[ tauri:: command]
@@ -34,6 +35,31 @@ fn read_folder(path: String) -> Vec<String> {
34
35
files
35
36
}
36
37
38
+ /// 读取一个文件夹中的全部文件,递归的读取
39
+ /// 如果文件夹不存在,返回空列表
40
+ /// fileExts: 要读取的文件扩展名列表,例如:[".txt", ".md"]
41
+ #[ tauri:: command]
42
+ fn read_folder_recursive ( path : String , fileExts : Vec < String > ) -> Vec < String > {
43
+ let mut files = Vec :: new ( ) ;
44
+ if let Ok ( entries) = std:: fs:: read_dir ( path) {
45
+ for entry in entries {
46
+ if let Ok ( entry) = entry {
47
+ if entry. path ( ) . is_file ( ) {
48
+ if let Some ( file_name) = entry. file_name ( ) . to_str ( ) {
49
+ if fileExts. iter ( ) . any ( |ext| file_name. ends_with ( ext) ) {
50
+ files. push ( file_name. to_string ( ) ) ;
51
+ }
52
+ }
53
+ } else if entry. path ( ) . is_dir ( ) {
54
+ let mut sub_files = read_folder_recursive ( entry. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) , fileExts. clone ( ) ) ;
55
+ files. append ( & mut sub_files) ;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ files
61
+ }
62
+
37
63
38
64
/// 删除文件
39
65
#[ tauri:: command]
Original file line number Diff line number Diff line change 11
11
使用 monorepo 管理项目,主要分为 app(应用程序本体) 和 docs(软件官网) 两个部分。
12
12
13
13
使用 pnpm 作为包管理工具。
14
+
15
+ ## 代码要求
16
+
17
+ rust中的函数提供给前端调用,函数在运行中绝对不能出现报错,必须要保证函数内部捕获所有可能出现的错误,函数的健壮性。否则会导致程序直接闪退
You can’t perform that action at this time.
0 commit comments