File.Delete not deleting file

  • Thread starter Thread starter Salman Zari Ghanvi
  • Start date Start date
S

Salman Zari Ghanvi

When the following code is execute and the file already exists, the file is
not actually deleted (in file properties - created date does not change) -
but only the modified and accessed date changes.

No exception is raised.

How can I ensure that file is actually deleted? I want to raise create event
for another application which is monitoring this folder similar to file
system watcher.

Thanks.


if (!File.Exists(fileName))
{
File.Delete(fileName);
}

using (StreamWriter sw = new StreamWriter(fileName,false))
{
sw.Write(content);
sw.Flush();
}
 
Your code says to delete the file if it does *not* exist. Which really
makes no sense, since if it doesn't exist, there is nothing to delete.
Sounds like you never actually stepped into this code. Take the '!' out of
the if statement.
 
Actually, I found that my actual code didnt had that (!)...

I ran this through debug mode (step by step) and saw the file getting
disappear. But on the creation step, I see the same behaviour: the file is
created with the old date - while the accessed and modified are current.

Can anyone try to reproduce it? (after correct my original posted code).

Thanks.
 
Found the solution:
Its an OS 'feature' called tunneling. mskb:12190 (file system tunneling
capabilities).

Problem was fixed after making the thread sleep for 15 seconds (default
value - can be changed thru registry) b/w delete and recreate.
 
Hi Salman

I have got some clue on deleting a file that does not exist. Unfortunately, I think its only possible using Java, not sure about .NET

If you wanna know, then in that case I will need to meet you in person as I can demonstrate this only on my laptop (not on any other machine)

I am coming to MDW, IL on Jan 9 - 10th. Let me know if we can meet.

c u .. reply me at
makcalif **at** yahhh0000 dot com
 
Back
Top