-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How find path relative to walkdir-root #5
Comments
Actually, I would prefer if the |
@purew Perhaps I'm missing something, but it seems easy enough to get what you want with let root = "/foo/bar/baz".to_owned();
for ent in WalkDir::new(&root) {
let ent = ent.unwrap();
println!("relative path: {}", ent.path().strip_prefix(&root).unwrap());
} Apologies if there are any errors, the above code was not checked by a compiler. |
Aye, I found strip_prefix shortly after writing this. It just felt a little unnecessary to form the absolute path and then deconstruct it again, compared to returning relative path and joining with root if absolute path if desired. I wonder if not the relative path is the more common usecase... |
@purew It's not a decision that is completely under the control of this library. I note that I have no idea what the more common use case is. Even if we did add a new |
I agree then. I was just initially a bit surprised after having used python's |
Hello,
I'm looking for an easy way to find the relative path between dir given to
WalkDir::new
and found files. The docstring below fromDirEntry
says that thepath()
is formed by joining theWalkDir::new
-path with the relative path I'm interested in, below called "file name of this entry". But thefile_name()
logically only returns the filename, not the dirs between...The text was updated successfully, but these errors were encountered: