Prevent Windows Explorer from interfering with Directory operations.
- by Bruno Martinez
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?