I'm sure there is an API or two involved, so I'm posting this here.
I need to be able to retrieve, and display, the full path to the Recent Documents folder. How would I do that?
Printable View
I'm sure there is an API or two involved, so I'm posting this here.
I need to be able to retrieve, and display, the full path to the Recent Documents folder. How would I do that?
VB Code:
Option Explicit Private Const SPECIALFOLDER_PROGRAMS = 2 '// Program Files Private Const SPECIALFOLDER_DOCUMENTS = 5 '// My Documents Private Const SPECIALFOLDER_FAVORITES = 6 '// Favourites Private Const SPECIALFOLDER_STARTUP = 7 '// Startup Folder Private Const SPECIALFOLDER_RECENT = 8 '// Recent Documents Private Const SPECIALFOLDER_SENDTO = 9 '// Send To Folder Private Const SPECIALFOLDER_STARTMENU = 11 '// Start Menu Private Const SPECIALFOLDER_DESKTOPFOLDER = 16 '// Desktop folder Private Const SPECIALFOLDER_NETHOOD = 19 '// NetHood Folder Private Const MAX_PATH As Integer = 260 Private Type HITEMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As HITEMID End Type Private Declare Function SHGetSpecialFolderLocation Lib "Shell32.dll" _ (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long Private Declare Function SHGetPathFromIDList Lib "Shell32.dll" Alias _ "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Private Function FindSpecialFolder(lngSpecialFolder As Long) As String Dim sPath As String Dim ItemID As ITEMIDLIST ' Info is stored in the IDL structure. FindSpecialFolder = "" If SHGetSpecialFolderLocation(Form1.hWnd, lngSpecialFolder, ItemID) = 0 Then ' Get the path from the ID list, and return the folder. sPath = Space$(MAX_PATH) If SHGetPathFromIDList(ByVal ItemID.mkid.cb, ByVal sPath) Then FindSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "\" End If End If End Function Private Sub Command1_Click() Dim sMyFolder As String sMyFolder = FindSpecialFolder(SPECIALFOLDER_RECENT) Text1.Text = sMyFolder End Sub