Directory c:\test has 50 or so files in it, no subdirectories.
If IO.Directory.Exists("C:\test") Then IO.Directory.Delete("C:\test", True) End If IO.Directory.CreateDirectory("C:\test")
Drive C is Intel's X25-M80 SSD drive, OS is Windows 7 64 bit with TRIM support, Visual Studio is 2008 with target framework 3.5. When above code is executed, CreateDirectory breaks code execution without an (visible) exception. After much headache I found that Delete is not yet done by the time code execution gets to CreateDirectory. If I modify my code like this:
If IO.Directory.Exists("C:\test") Then IO.Directory.Delete("C:\test", True) End If Threading.Thread.Sleep(2000) IO.Directory.CreateDirectory("C:\test")
then everything works as expected.
My questions beside the obvious WTF here are:
I've had problems with this before, but this is not specific to SSD drives. You would be far better off doing a move then delete:
if(Directory.Exists(dirpath)) { string temppath = dirpath + ".deleted"; Directory.Move(dirpath, temppath); Directory.Delete(temppath, true); } Directory.Create(dirpath);
The other way to deal with it is to loop until complete:
if(Directory.Exists(dirpath)) { Directory.Delete(dirpath, true); int limit = 100; while(Directory.Exists(dirpath) && limit-- > 0) Thread.Sleep(0); } Directory.Create(dirpath);
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