Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out if a file is already created in a StorageFolder

If I have a metro StorageFolder, I can get a file using GetFileAsync(fileName).

However, how do I know if the file exists in the first place? Right now, I catch an exception but it does not seem like the right thing to do.

like image 754
user380719 Avatar asked Apr 08 '12 22:04

user380719


1 Answers

According to Microsoft, they want us to catch the exception. The reasoning they gave me is that them providing a File.Exists API would open you up to race conditions where the file's existance might change between when you check and when you try to use the file. Because of that race condition, you have to write exception handling code anyways and once you've done that, there's little to be gained by calling a File.Exists API. I don't agree with this argument but it's what we're stuck with.

like image 136
Robert Levy Avatar answered Oct 30 '22 03:10

Robert Levy