问题
Strange problem occurs on the production platform (64 bit win 2008 server).
It is connected with File.Exists
and File.Delete
methods...
On test platform in debug (win xp), etc it works fine. On Server 2008 for the first few timesFile.Exists
reported true
for the file which didn't exist ...
When I Was doing further tests File.Exists
finally reported false for the file which didn't exist.
But File.Delete
hadn't thrown any error when attempting to delete the file which didn't exists ...
What is happening ... ?
I read somewhere that system virtualation could mess the things up ... but hasn't found any file in: %userprofile%\AppData\Local\VirtualStore
回答1:
File.Delete
on MSDN:
public static void Delete(string path)
If the file to be deleted does not exist, no exception is thrown.
So. it's deliberated.... no true
\ false
and no exceptions, just delete the file if it exist.
Note about File.Exist
:
public static bool Exists(string path)
Return Value Type: System.Boolean
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is Nothing, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.
MSDN
来源:https://stackoverflow.com/questions/9884807/file-delete-doesnt-throw-error-when-the-file-doesnt-exist