Re: DirectoryInfo.Exists still returns False after directory created.
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 24 Nov 2005 22:22:24 +0100
"Phil Rodgers" <PhilR@xxxxxxxxxxxxxxxxxx> wrote in message
news:4FA27F2B-4BB0-423E-82C9-4BCC6DACBE76@xxxxxxxxxxxxxxxx
> 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
info.Exists returns the state at the time you created the instance of the
DirectoryInfo class. That means you have to create a new instance after you
created the directory.
Willy.
.
- Prev by Date: Re: Missing ASP.NET tab in IIS after 2.0 installation
- Next by Date: Re: how do i create a new file -- in memory?
- Previous by thread: Re: Missing ASP.NET tab in IIS after .NET Framework 2.0 installation.
- Next by thread: Re: DirectoryInfo.Exists still returns False after directory created.
- Index(es):
Relevant Pages
|