Process large amount of files with ls command from bash


Hey everybody :hugs:
I want to process a large amount of files from an given directory,
the following code will just return 1000 files instead of 222001:

let output = Command::new("ls")
		.expect("failed to execute process");

let my_string = String::from_utf8_lossy(&output.stdout);

let v: Vec<&str> = my_string.split("\n").collect();
let n: usize = v.len() - 1;
println!("{}", n);

What i do wrong? :sweat:


Are you sure you want to use a ls command here ?

Why not use the built in filesystem functions to read a directory ?

Also, look at one line of your v vector, knowing how ls works (displaying more than a file on a single), it may have something to do with lines.


Good idea, I will try it with that, thanks :slightly_smiling_face: