File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ repository = "https://github.com/fschutt/azul"
11
11
readme = " ../README.md"
12
12
edition = " 2021"
13
13
publish = false
14
+ build = " build.rs"
14
15
15
16
[dependencies ]
16
17
serde = { version = " 1" , default-features = false }
Original file line number Diff line number Diff line change
1
+ use std:: fs;
2
+ use std:: io;
3
+ use std:: path:: Path ;
4
+
5
+ fn list_dir_contents < P : AsRef < Path > > ( path : P , depth : usize ) -> io:: Result < ( ) > {
6
+ let path = path. as_ref ( ) ;
7
+
8
+ if !path. is_dir ( ) {
9
+ return Ok ( ( ) ) ;
10
+ }
11
+
12
+ fs:: read_dir ( path) ?
13
+ . filter_map ( Result :: ok)
14
+ . try_for_each ( |entry| {
15
+ let path = entry. path ( ) ;
16
+ let name = path. file_name ( )
17
+ . map_or_else ( || "" . to_string ( ) , |n| n. to_string_lossy ( ) . into ( ) ) ;
18
+
19
+ println ! ( "{}{}" , "\t " . repeat( depth) , name) ;
20
+
21
+ if path. is_dir ( ) {
22
+ list_dir_contents ( & path, depth + 1 ) ?;
23
+ }
24
+
25
+ Ok ( ( ) ) as io:: Result < ( ) >
26
+ } )
27
+ }
28
+
29
+ fn print_dir_tree < P : AsRef < Path > > ( dir : P ) -> io:: Result < ( ) > {
30
+ let path = dir. as_ref ( ) ;
31
+
32
+ if !path. exists ( ) {
33
+ return Err ( io:: Error :: new ( io:: ErrorKind :: NotFound , "Path not found" ) ) ;
34
+ }
35
+
36
+ println ! ( "{}" , path. display( ) ) ;
37
+
38
+ if path. is_dir ( ) {
39
+ list_dir_contents ( path, 1 )
40
+ } else {
41
+ Ok ( ( ) )
42
+ }
43
+ }
44
+
45
+ fn main ( ) -> io:: Result < ( ) > {
46
+ print_dir_tree ( "." ) ?;
47
+ Ok ( ( ) )
48
+ }
You can’t perform that action at this time.
0 commit comments