aewarnick Posted February 28, 2003 Posted February 28, 2003 (edited) How can I reference the windows directory for any os in C#? You can do it in batch files and should be able to in C#. Edited February 28, 2003 by aewarnick Quote C#
*Gurus* divil Posted February 28, 2003 *Gurus* Posted February 28, 2003 You can use Environment.SystemDirectory to retreive the path to the system directory, and use string manipulation or the methods of the Path class to get just the Windows directory from that. As far as I know there's no framework way to get just the Windows directory, but I'd like to be proved wrong. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted February 28, 2003 Author Posted February 28, 2003 I hope there is a method to get just the windows dir. If I just used the method above would it be the same for ever windows os? Ex: mine is System32. Quote C#
CaNaDiAn BaCoN Posted March 3, 2003 Posted March 3, 2003 Use DirectoryInfo System (or System32) is always a direct sub-folder of Windows (or Win2k/NT or whatever) so use the following code: VB: Public Function GetWinDir() as String 'Create a directory info structure of C:\Win2k\System32 or C:\Windows\system, etc. Dim di as New DirectoryInfo(Environment.SystemDirectory) 'Return the full path of its parent Return di.Parent.FullName End Function C#: public String GetWinDir() { //Create a directory info structure of C:\Win2k\System32 or C:\Windows\system, etc. DirectoryInfo di = new DirectoryInfo(Environment.SystemDirectory) // Return the full path of its parent return di.Parent.FullName } No matter the Windows version this should return the windows dir Quote
aewarnick Posted March 4, 2003 Author Posted March 4, 2003 Oh! Great! I'll try it out! I like your quote, it's witty. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.