mirror of
https://github.com/jht5945/finding.git
synced 2025-12-27 21:20:05 +08:00
add list dir
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -1,6 +1,10 @@
|
||||
extern crate argparse;
|
||||
extern crate rust_util;
|
||||
|
||||
use std::{
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||
use rust_util::*;
|
||||
|
||||
@@ -15,6 +19,35 @@ Written by Hatter Jiang
|
||||
"#, VERSION);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
fn check_path(path: &Path) {
|
||||
//println!("-------------- {:?} {}", path, path.is_dir());
|
||||
}
|
||||
|
||||
fn list_dir(dir: &Path, fnc: fn(&Path) -> ()) -> XResult<()> {
|
||||
list_dir_with_depth_check(&mut 0u32, dir, fnc)
|
||||
}
|
||||
|
||||
fn list_dir_with_depth_check(depth: &mut u32, dir: &Path, fnc: fn(&Path) -> ()) -> XResult<()> {
|
||||
if *depth > 100u32 {
|
||||
// TODO error: return Err(Box::new("depth"));
|
||||
}
|
||||
for e in dir.read_dir()? {
|
||||
let ee = e?;
|
||||
println!("{}:{} {:?} {}", depth, " ".repeat(*depth as usize), ee, ee.path().as_path().is_file());
|
||||
if ee.path().as_path().is_dir() {
|
||||
*depth += 1;
|
||||
match list_dir_with_depth_check(depth, ee.path().as_path(), fnc) {
|
||||
Err(_) => (), // TODO ...
|
||||
Ok(_) => (),
|
||||
}
|
||||
*depth -= 1;
|
||||
}
|
||||
fnc(ee.path().as_path());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut version = false;
|
||||
let mut target = String::from("text");
|
||||
@@ -36,12 +69,14 @@ fn main() {
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------
|
||||
println!("{:?}", get_home());
|
||||
println!("{:?}", get_home_path());
|
||||
println!("{:?}", get_absolute_path("."));
|
||||
println!("{:?}", get_absolute_path("../"));
|
||||
println!("{:?}", get_absolute_path("~"));
|
||||
println!("{:?}", get_absolute_path("~/.jssp"));
|
||||
println!("{:?}", get_absolute_path("~/.jsspx"));
|
||||
|
||||
list_dir(get_absolute_path("~").unwrap().as_path(), check_path).ok();
|
||||
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user