File.Delete does not throw an error when the file does not exist

A strange problem arises on the production platform (server with a 64-bit win of 2008). It is associated with the File.Exists and File.Delete ... File.Delete .

On a test platform in debug (win xp), etc. It works great. On server 2008 for the first few times
File.Exists reported true for a file that does not exist ...

When I did further tests, File.Exists finally reported false for a file that was not there.
But File.Delete did not make mistakes when trying to delete a file that did not exist ...

What's happening...?

I read somewhere that system virtualization can ruin things ... but I did not find a single file: %userprofile%\AppData\Local\VirtualStore

+4
source share
1 answer

File.Delete on MSDN :

 public static void Delete(string path) 

If the file to be deleted does not exist, an exception will not be thrown.

So. he discussed .... no true \ false and no exceptions, just delete the file if it exists.

Note about File.Exist :

 public static bool Exists(string path) 

Return Value Type: System.Boolean

true if the caller has the necessary permissions and the path contains the name of an existing file; otherwise false . This method also returns false if the path is Nothing, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, an exception is not thrown and the method returns false regardless of the path.

MSDN

+22
source

Source: https://habr.com/ru/post/1403598/


All Articles