Re: DirectoryInfo.Exists still returns False after directory created.




"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.




.



Relevant Pages

  • Re: Gandhi and Ambedkar
    ... dalits, while not accepted "formally" into the framework, were treated ... like lowest of shudras and expoited economically, ... Prev by Date: ...
    (soc.culture.indian)
  • Work Flow
    ... framework. ... Regards ... - Atul Sureka ... Prev by Date: ...
    (microsoft.public.dotnet.faqs)
  • Work Flow
    ... framework. ... Regards ... - Atul Sureka ... Prev by Date: ...
    (microsoft.public.dotnet.framework)
  • Re: How to start a thread with a parameter in framework 2.0?
    ... I have heard theres a new way to start threads with parameters in ... framework 2.0, does anyone know how to do that? ... Appriciate any code examples. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)