Results 1 to 3 of 3

Thread: Get My Documents Path

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2005
    Location
    Indiana
    Posts
    451

    Question Get My Documents Path

    I am trying to find a way to get the My Documents path. I have searched the forum, but haven't found anything helpful. I need to get it for all windows os from 98 to present. Anyone know how I can do that?

    Thank you for your help.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Get My Documents Path

    Here is a sample from the allapi network - use CSIDL_PERSONAL for what you need:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const CSIDL_PERSONAL = &H5
    4. Private Const NOERROR = 0
    5.  
    6. Private Type SHTEMID
    7.     cb As Long
    8.     abID As Byte
    9. End Type
    10. Private Type ITEMIDLIST
    11.     mkid As SHTEMID
    12. End Type
    13.  
    14. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
    15.     (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
    16.  
    17. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
    18.     "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    19.  
    20. Private Sub Form_Load()
    21.     Debug.Print "My Documents path: " & GetSpecialfolder(CSIDL_PERSONAL)
    22. End Sub
    23.  
    24. Private Function GetSpecialfolder(CSIDL As Long) As String
    25. Dim r As Long
    26. Dim IDL As ITEMIDLIST
    27. Dim Path$
    28.  
    29.     'Get the special folder
    30.     r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    31.     If r = NOERROR Then
    32.         'Create a buffer
    33.         Path$ = Space$(512)
    34.         'Get the path from the IDList
    35.         r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
    36.         'Remove the unnecessary chr$(0)'s
    37.         GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
    38.         Exit Function
    39.     End If
    40.     GetSpecialfolder = ""
    41. End Function
    EDIT: sample from allapi was full of bugs so I modified it.

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Get My Documents Path

    try the HOMEPATH Environment Variable:
    VB Code:
    1. MsgBox Environ("HOMEPATH")
    Show Appreciation. Rate Posts.

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