#How to check if a path is file, dir or does not exist cross platform?

1 messages · Page 1 of 1 (latest)

severe hedge
#

Hello. I'm looking for a way to go through a list of paths that I got as command line arguments and find out for each one if it is a file or a directory or does not exist. It should work on linux, windows and macos.

old plank
#

there’s also an error for trying to open a directory but I forgot what it’s called

#

probably error.IsDir or something

severe hedge
#

I've seen an issue that suggests I can't rely on the error.IsDir on all platforms. https://github.com/ziglang/zig/issues/5732

Although I read a bit about it I had hoped to be able to avoid to dive into the details (and testing on different OS) and "just" get a solution that works on the 3 mentioned OS.

GitHub

From #5717: I didn't include a read-only test because I was unsure about how to handle the differing errors per-platform, as mentioned here: On Linux, when opening a file with read-only permiss...

#

Reading a bit more in those issues it looks like the current state is that it's not there yet but talked about/planned.

severe hedge
#

Thank you. Do you know why error.AccessDenied also calls fmtPathDir?

round sand
#

I assume that's the error you get on windows when you try to open a dir as a file