Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if file exists in a Windows Store App?

Is there any other way of checking whether a file exists in a Windows Store app?

try {     var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.xml");     //no exception means file exists } catch (FileNotFoundException ex) {      //find out through exception  } 
like image 324
Haris Hasan Avatar asked Dec 24 '11 17:12

Haris Hasan


People also ask

How check if file exists folder?

To check for specific files use File. Exists(path) , which will return a boolean indicating wheter the file at path exists.

How can I tell if a text file exists?

To check if a file exists, you pass the file path to the exists() function from the os. path standard library. If the file exists, the exists() function returns True . Otherwise, it returns False .


1 Answers

According to the accepted answer in this post, there is no other way at the moment. However, the File IO team is considering changing the the api so that it returns null instead of throwing an exception.

Quote from the linked post:

Currently the only way to check if a file exists is to catch the FileNotFoundException. As has been pointed out having an explicit check and the opening is a race condition and as such I don't expect there to be any file exists API's added. I believe the File IO team (I'm not on that team so I don't know for sure but this is what I've heard) is considering having this API return null instead of throwing if the file doesn't exist.

like image 72
keyboardP Avatar answered Sep 20 '22 18:09

keyboardP