0

I want to create a file in (drive letter):\Program Files\myprog\file.ext where (drive letter) is the drive letter where windows is installed (or the default drive). Is there an easy Windows API method to retrieve it?

Thanks

PS, here is what I'm currently using:

string mainDrive = "";
      foreach (string drive in Directory.GetLogicalDrives())
      {
        Console.WriteLine(drive);
        if (Directory.Exists(drive + "WINDOWS\\System32") || Directory.Exists(drive + "WINDOWS NT\\System32"))
        {
          mainDrive = drive;
          break;
        }
      }
      if (mainDrive.Equals(""))
      {
        // couldn't find default directory, should probably do some error checking
        mainDrive = "C:\\";
      }
2
Contributors
2
Replies
4
Views
8 Years
Discussion Span
Last Post by axfv
0

I believe you can use "%programfiles%" and it should result in the path [Default drive letter]:\Program Files\.

Edit: If not you can use "%SystemDrive%\\Program Files\\" .

0

that worked, thanks a lot! Had to use Environment.GetSystemVariable("%SystemDrive%")

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.