Home > How-To Library > System & API
How to get special folders
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** 'Declarations to find special folders 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 Type SHITEMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As SHITEMID End Type Private Const MAX_PATH As Integer = 260 Public Function fGetSpecialFolder(ByVal CSIDL As Long) As String 'This function will find My documents path. 'value Result '2 C:\Documents and Settings\<USERNAME>\Start Menu\Programs '5 C:\Documents and Settings\<USERNAME>\My Documents '6 C:\Documents and Settings\<USERNAME>\Favorites '7 C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Startup '8 C:\Documents and Settings\<USERNAME>\Recent '9 C:\Documents and Settings\<USERNAME>\SendTo '11 C:\Documents and Settings\<USERNAME>\Start Menu '13 C:\Documents and Settings\scsrinivasan\My Documents\My Music '16 C:\Documents and Settings\<USERNAME>\Desktop '19 C:\Documents and Settings\<USERNAME>\NetHood '20 C:\WINNT\Fonts '21 C:\Documents and Settings\<USERNAME>\Templates '22 C:\Documents and Settings\All Users\Start Menu '23 C:\Documents and Settings\All Users\Start Menu\Programs '24 C:\Documents and Settings\All Users\Start Menu\Programs\Startup '25 C:\Documents and Settings\All Users\Desktop '26 C:\Documents and Settings\<USERNAME>\Application Data '27 C:\Documents and Settings\<USERNAME>\PrintHood '28 C:\Documents and Settings\<USERNAME>\Local Settings\Application Data '31 C:\Documents and Settings\All Users\Favorites '32 C:\Documents and Settings\<USERNAME>\Local Settings\Temporary Internet Files '33 C:\Documents and Settings\<USERNAME>\Cookies '34 C:\Documents and Settings\<USERNAME>\Local Settings\History '35 C:\Documents and Settings\All Users\Application Data '36 C:\WINNT37 C:\WINNT\system32 '38 C:\Program Files '39 C:\Data\My Pictures '40 C:\Documents and Settings\<USERNAME> '41 C:\WINNT\system32 '43 C:\Program Files\Common Files '45 C:\Documents and Settings\All Users\Templates '46 C:\Documents and Settings\All Users\Documents '47 C:\Documents and Settings\All Users\Start Menu\Programs\Administrative Tools '48 C:\Documents and Settings\<USERNAME>\Start Menu\Programs\Administrative Tools Dim sPath As String Dim IDL As ITEMIDLIST On Error GoTo fGetSpecialFolder_Error fGetSpecialFolder = "" If SHGetSpecialFolderLocation(0, CSIDL, IDL) = 0 Then sPath = Space$(MAX_PATH) If SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal sPath) Then fGetSpecialFolder = Left$(sPath, InStr(sPath, vbNullChar) - 1) & "" End If End If On Error GoTo 0 Exit Function fGetSpecialFolder_Error: RaiseEvent ErrRepo("fGetSpecialFolder", Err.Number, Err.Description, False) Err.Clear Resume Next End Function
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.