I am trying to get file/folder metadata. If that fails then I assume non-existence of that file/folder. Probably should be faster than listing all items in folder. But I would prefer built-in solution anyway.
Yes. If you get an error the file doesn’t exist. You don’t have to loop through all the files. If you know the name of the file and already have a reference to the folder then you can use that.
Update: I have come to discover that the error code is not reliable to indicate no such file or directory as it seems to be platform dependent. For example, on Windows it throws error code -4058 and on Mac it throws error code -2. For this reason I’ve decided to compare on the error.message value and not the error.code value in my catch block.