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
Right click the bad file and click Add to Archives. Then in the options select to delete original file after compression. Leave other options same and proceed. Bad file will be deleted and a compressed file will be created in its place.
If the file to be deleted does not exist, no exception is thrown.
To delete a file if exists in Python, use the os. path. exists() and os. remove() method.
The File. Delete(path) method is used to delete a file in C#. The File. Delete() method takes the full path (absolute path including the file name) of the file to be deleted.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With