I have below code which I run for several iterations in different times of the day.
Most of the times, it runs as expected but some times it has some issues.
Please find the code below,
try
{
string filePath = Path.GetTempFileName(); //this creates a 0 kb temp file.
if (File.Exists(filePath))
File.Delete(filePath); //it goes here means file exists and no error is being thrown.
else
Console.WriteLine("File:" + filePath + " didn't get created");
if (File.Exists(filePath))
Console.WriteLine("file still exist:" + filePath); //even though no errors, it still find the file
}
catch(Exception ex)
{
Console.WriteLine("Error Occured: " + ex.ToString()); //It doesn't go here.
}
Here I cannot understand, if the code is able to detect that file exists and try to delete it. It cannot delete the file and No exception is being thrown too.
Am I missing anything?