Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Wierd IO

Wierd IO

Scheduled Pinned Locked Moved C#
csharpcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tatham
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • T Tatham

      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

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups