Results 1 to 4 of 4

Thread: Getting Windows Directory

  1. #1

    Thread Starter
    Hyperactive Member mastermind94's Avatar
    Join Date
    Jun 2000
    Location
    Montréal, Canada
    Posts
    441

    Post

    How can I get the windows Directory?

  2. #2
    Guest
    Use the GetWindowsDirectory API.

  3. #3
    Guest
    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

  4. #4
    Lively Member
    Join Date
    Apr 2000
    Posts
    110

    Windows dir using API...

    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.

    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
    Now, in a form or module, put the following code to get the windows path:

    Code:
    Dim win As New Windows
    'Display the windows directory
    Msgbox win.GetWinDir
    Hope this helps!

    Latrz

    REM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width