Hi !
I want to check if a file name starts with a specific string.
In that way, I'm using 'starts_with' on path.
I saw that this need to be the same base path, but when I tried to check for the filename it fails.
I tried this code:
// Dir '/mydir' contains :
// - image.jpg
// - doc.pdf
// - video.mp4
// - video.mp4-720p.vp8
// - video.mp4-1080p.vp8
// - video.mp4-720p.vp9
// - video.mp4-1080p.vp9
// - other-video.mp4
// So dirpath = "/mydir" and starting_with = "video.mp4"
fn remove_file(&self, dirpath: &PathBuf, starting_with: &str){
// if !dirpath.is_dir() {
// return err;
// }
let readdir = match read_dir(&dirpath) {
Ok(r) => r,
Err(e) => {
// return err;
}
};
let starts_with = dirpath.join(starting_with);
let files: Vec<PathBuf> = readdir
.filter_map(|r| r.ok())
.map(|f| f.path())
.filter(|f| f.is_file() && f.starts_with(starts_with))
.collect();
debug!(
"{} files found starting with '{}' in '{}'",
files.len(),
starting_with,
dirpath.display()
);
// some code on 'files'
}
I expected to see this happen:
the log must print '5' (the 4 transcoded video + the original one)
Instead, this happened:
1 file found (only the original)
rustc --version --verbose
:
rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-unknown-linux-gnu
release: 1.70.0
LLVM version: 16.0.2
So do I misundertand something ? Or is it a problem in the API ?
(I think that's me at 95% but don't know where is my mistake)
I am wondering if I have to get OsStr and next &str to check it, but it maybe will not be really clean to that (a lot of options to handle)
Thank you for your help !