Wierd IO
-
Hi guys, I am currently implementing an application which needs to support paths like: %windir%\Microsoft.NET\Framework\ The pointers (eg %windir%) are supported by .NET, so i can access file listings easily. However, Directory.Exists returns some wierd results: Directory.Exists("%windir%") => false Directory.Exists("%windir%\Microsoft.NET\") => true Does anyone know of a way to validate these directories properly. I can just request a directory listing, and wait for an exception but this isn't good coding and will slow down the process too much as potentially hundreds will need to be evaluated. Thanks, Tatham Oddie Developer, SSW (www.ssw.com.au
-
Hi guys, I am currently implementing an application which needs to support paths like: %windir%\Microsoft.NET\Framework\ The pointers (eg %windir%) are supported by .NET, so i can access file listings easily. However, Directory.Exists returns some wierd results: Directory.Exists("%windir%") => false Directory.Exists("%windir%\Microsoft.NET\") => true Does anyone know of a way to validate these directories properly. I can just request a directory listing, and wait for an exception but this isn't good coding and will slow down the process too much as potentially hundreds will need to be evaluated. Thanks, Tatham Oddie Developer, SSW (www.ssw.com.au
These are actually called environment variables, not pointers. Windows 98 and ME don't always support the same environment variables as Windows NT. It is better to use
Environment.GetFolderPath
, since this is supported by all operating systems that currently support the CLR. The functions that this method use are actually used by Windows Explorer, Windows Installer, various Microsoft and non-Microsoft applications, and the .NET Framework, of course. It is far more reliable and more robust to use this like so:string system = Environment.GetFolderPath(Environment.SpecialFolder.System);
string windir = Directory.GetParent(system).FullName;
string framework = Path.Combine(windir, "Microsoft.NET\\Framework");A little long-winded, but - as I said - is supported on any OS supporting the CLR and uses the paths that administrators might set up in a roaming profile or for home directories and what not (overriding the defaults).
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----