-
Notifications
You must be signed in to change notification settings - Fork 83
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 to check if a given path is a directory? #170
Comments
For example : in directory #[derive(RustEmbed)]
#[folder = "embed/"]
struct Asset;
fn is_dir(path:&str) -> bool {
Asset::is_dir("embed/some_dir")
} |
We don't have that API, but it would be a good addition to https://docs.rs/rust-embed/6.3.0/rust_embed/struct.Metadata.html |
Fixed in #193 |
@markijohn Could you please elaborate on your usecase, in what setting would you need to know why an entry is a directory? The embedded files are known at compile time otherwise they are not included in the binary. |
Reopening since the PR got reverted. @markijohn can you elaborate on your use case? What are you trying to achieve with an |
I am sorry for the late comment. This was arbitrarily modified a long time ago to the following, but I wanted to know if it could be done without 'iter()' for optimization when there are a lot of embedded files and directories.
#[macro_use]
extern crate rust_embed;
#[derive(RustEmbed)]
#[folder = "embed/"]
struct Asset;
fn is_exist_dir(path:&str) -> bool {
// Asset::is_dir( path ) ?
if path.ends_with("/") {
Asset::iter().find( |v| v.starts_with(path) ).is_some()
} else {
// let added_pathsep = format!("{}/", path);
// Asset::iter().find( |v| v.starts_with( &added_pathsep ) ).is_some()
Asset::iter().find( |v| v.starts_with( path ) && v[path.len() ..].starts_with('/') ).is_some()
}
}
fn main() {
let user_input = "somedir";
assert!( is_exist_dir(user_input) );
let user_input = "somefile";
assert!( !is_exist_dir(user_input) );
} |
Don't support it? Or am I can't to find it?
The text was updated successfully, but these errors were encountered: