G
Guest
In the 1.1 framework, I've come across some peculiar behaviour in
DirectoryInfo.Exists. If you create a DirectoryInfo for a directory that
doesn't exist, DirectoryInfo.Exists correctly returns False. However, if you
then call DirectoryInfo.Create to create the directory, DirectoryInfo.Exists
still returns False even though the directory has been successfully created.
This is a little counterintuitive to say the least.
The following code:
string test = @"C:\test";
if (Directory.Exists(test))
{
Directory.Delete(test, true /*recursive*/);
}
Console.WriteLine("Directory.Exists(test): {0}",
Directory.Exists(test));
DirectoryInfo info = new DirectoryInfo(test);
Console.WriteLine("info.Exists: {0}", info.Exists);
Console.WriteLine("info.Create();");
info.Create();
Console.WriteLine("info.Exists: {0}", info.Exists);
Console.WriteLine("Directory.Exists(test): {0}",
Directory.Exists(test));
produces this output:
Directory.Exists(test): False
info.Exists: False
info.Create();
info.Exists: False
Directory.Exists(test): True
It seems to me that this is, well, wrong, isn't it?
Phil Rodgers
DirectoryInfo.Exists. If you create a DirectoryInfo for a directory that
doesn't exist, DirectoryInfo.Exists correctly returns False. However, if you
then call DirectoryInfo.Create to create the directory, DirectoryInfo.Exists
still returns False even though the directory has been successfully created.
This is a little counterintuitive to say the least.
The following code:
string test = @"C:\test";
if (Directory.Exists(test))
{
Directory.Delete(test, true /*recursive*/);
}
Console.WriteLine("Directory.Exists(test): {0}",
Directory.Exists(test));
DirectoryInfo info = new DirectoryInfo(test);
Console.WriteLine("info.Exists: {0}", info.Exists);
Console.WriteLine("info.Create();");
info.Create();
Console.WriteLine("info.Exists: {0}", info.Exists);
Console.WriteLine("Directory.Exists(test): {0}",
Directory.Exists(test));
produces this output:
Directory.Exists(test): False
info.Exists: False
info.Create();
info.Exists: False
Directory.Exists(test): True
It seems to me that this is, well, wrong, isn't it?
Phil Rodgers