How can I get the windows Directory?
Printable View
How can I get the windows Directory?
Use the GetWindowsDirectory API.
Code:Public Function DirExists(ByVal strDirName As String) As Integer
Dim strDummy As String
On Error Resume Next
If Right$(strDirName, 1) <> "\" Then
strDirName = strDirName & "\"
End If
strDummy = Dir$(strDirName & "*.*", vbDirectory)
DirExists = Not (strDummy = vbNullString)
Err = 0
End Function
Usage:
If DirExists("C:\Windows\") Then
'do whatever
End If
To get the path to the windows folder, as Megatron said, use the GetWindowsDirectory API function. Check out thte following sample code. The class file is called Windows.cls.
Now, in a form or module, put the following code to get the windows path:Code:'Windows.cls
Option Explicit
Private Declare Function GetWindowsDirectory Lib _
"kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) _
As Long
Public Function GetWinDir() As String
Dim strPath As String
Dim lngRet As Long
strPath = Space(256) 'String buffer
lngRet = GetWindowsDirectory(strPath, 256)
strPath = Left(strPath, lngRet) 'Trim the string
GetWinDir = strPath 'Return the path
End Function
Hope this helps!Code:Dim win As New Windows
'Display the windows directory
Msgbox win.GetWinDir
Latrz
REM