Prevent Windows Explorer from interfering with Directory operations.

Posted by Bruno Martinez on Stack Overflow See other posts from Stack Overflow or by Bruno Martinez
Published on 2010-04-27T01:21:05Z Indexed on 2010/04/27 1:23 UTC
Read the original article Hit count: 449

Filed under:
|
|
|

Sometimes, no "foo" directory is left after running this code:

string folder = Path.Combine(Path.GetTempPath(), "foo");
if (!Directory.Exists(folder))
    Directory.CreateDirectory(folder);
Process.Start(@"c:\windows\explorer.exe", folder);
Thread.Sleep(TimeSpan.FromSeconds(5));
Directory.Delete(folder, false);
Directory.CreateDirectory(folder);

It seems Windows Explorer keeps a reference to the folder, so the last CreateDirectory has nothing to do, but then the original folder is deleted. How can I fix the code?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Windows