fs::read_dir can locate a file but fs::read_to_str can't open it
I have some code where I need to parse a file to generate a character tree. However, the main access point is supposed to be through the directory.
Essentially, when I perform a read_dir on the directory, the correct file is found. Then the path of this new file is passed into a different function, and the new function tries to perform a read_to_string of the path.
At this point, the code panics with the error message "No such OS or Directory found". I checked the source code for read_to_string, and it appears that it uses File::open()? under the hood. Any ideas why this may be failing? I'm running ubuntu on a WSL system, btw.
Edit: I forgot to say before that the file and directory both have read permission for all users
Edit: Here is what I'm trying right now:
impl SharDirectory {
pub fn new(dir_path: &str) -> Result<Self> {
let entries = std::fs::read_dir(dir_path);
for entry in entries {
let entry = entry?;
let entry_type = entry.file_type()?;
.
.
.
} else if entry_type.is_file() {
let file = SharFile::new(entry.path().to_str().unwrap())?;
}
}
}
impl SharFile {
pub fn new(file_path: &str) -> Result<Self> {
println!("file path: {}", file_path); // prints proper file path from home directory
let file = std::fs::read_to_string(file_path);
.
.
.
}
}