Check whether a file exists in a auto generated directory

I have below folder strcuture

$ ls test_dir/abc/
file.txt

test_dir/ -> Created during runtime but has a constant name in all execution.
abc/ -> Created during runtime but name gets changed for every execution.

Since abc/ name is not a constant one, How I can confirm whether test_dir/auto_generated_dir/file.txt file actually created.

Use Path::exists.

for path::Exists we need a constant path but here name of abc/ changes everytime

Okay, let me clarify:

let mut path = PathBuf::from("test_dir");
loop {
    let dir = get_dynamically_generated_dir();
    path.push(dir);
    path.push("file.txt");
    if path.exists() {
        // Do stuff
    }
    path.pop(); path.pop();
}
3 Likes

Do you mean that the file is created by one process (which knows the name of the generated directory) and then checked by another one (which doesn't)?

That is not true. It works with any path.