Difference between revisions of "Special folders"
From HashVB
m (Used the new API link template) |
m (Added a few extra folder CSIDLs) |
||
Line 56: | Line 56: | ||
| My Pictures || CSIDL_MYPICTURES || &H27 || (user)\My Documents\My Pictures | | My Pictures || CSIDL_MYPICTURES || &H27 || (user)\My Documents\My Pictures | ||
|- | |- | ||
− | | My Music || || &H0D || (user)\My Documents\My Music | + | | My Music || CSIDL_MYMUSIC || &H0D || (user)\My Documents\My Music |
+ | |- | ||
+ | | My Videos || CSIDL_MYVIDEO || &H0E || (user)\My Documents\My Videos | ||
|- | |- | ||
| Common documents || CSIDL_COMMON_DOCUMENTS || &H2E || (all users)\Documents | | Common documents || CSIDL_COMMON_DOCUMENTS || &H2E || (all users)\Documents | ||
|- | |- | ||
− | | Common Pictures || | + | | Common Pictures || CSIDL_COMMON_PICTURES || &H36 || (all users)\Documents\My Pictures |
|- | |- | ||
− | | Common Music || || &H35 || (all users)\Documents\My Music | + | | Common Music || CSIDL_COMMON_MUSIC || &H35 || (all users)\Documents\My Music |
|- | |- | ||
− | | Common Videos || || &H37 || (all users)\Documents\My Videos | + | | Common Videos || CSIDL_COMMON_VIDEO || &H37 || (all users)\Documents\My Videos |
|- | |- | ||
! Start menu | ! Start menu | ||
Line 135: | Line 137: | ||
|} | |} | ||
<!-- | <!-- | ||
+ | CSIDL_DESKTOP As Long = &H0 'Desktop again (user)\Desktop | ||
CSIDL_INTERNET As Long = &H1 'Internet virtual folder | CSIDL_INTERNET As Long = &H1 'Internet virtual folder | ||
CSIDL_CONTROLS As Long = &H3 'My Computer\Control Panel | CSIDL_CONTROLS As Long = &H3 'My Computer\Control Panel | ||
CSIDL_PRINTERS As Long = &H4 'My Computer\Printers | CSIDL_PRINTERS As Long = &H4 'My Computer\Printers | ||
CSIDL_BITBUCKET As Long = &HA '{desktop}\Recycle Bin | CSIDL_BITBUCKET As Long = &HA '{desktop}\Recycle Bin | ||
+ | CSIDL_MYDOCUMENTS As Long = &HC | ||
CSIDL_DRIVES As Long = &H11 'My Computer | CSIDL_DRIVES As Long = &H11 'My Computer | ||
CSIDL_NETWORK As Long = &H12 'Network Neighbourhood | CSIDL_NETWORK As Long = &H12 'Network Neighbourhood | ||
Line 148: | Line 152: | ||
CSIDL_PROGRAM_FILESX86 As Long = &H2A 'Program Files folder for x86 apps (Alpha) | CSIDL_PROGRAM_FILESX86 As Long = &H2A 'Program Files folder for x86 apps (Alpha) | ||
CSIDL_PROGRAM_FILES_COMMONX86 As Long = &H2C 'x86 \Program Files\Common on RISC | CSIDL_PROGRAM_FILES_COMMONX86 As Long = &H2C 'x86 \Program Files\Common on RISC | ||
+ | CSIDL_CONNECTIONS As Long = &H31 | ||
+ | CSIDL_RESOURCES As Long = &H38 'C:\WINDOWS\Resources | ||
+ | CSIDL_RESOURCES_LOCALIZED As Long = &H39 | ||
+ | CSIDL_COMMON_OEM_LINKS As Long = &H3A | ||
+ | CSIDL_CDBURN_AREA As Long = &H3B '(user)\Local Settings\Application Data\Microsoft\CD Burning\ | ||
+ | CSIDL_COMPUTERSNEARME As Long = &H3D | ||
--> | --> | ||
Revision as of 11:01, 5 January 2007
This article is based on Visual Basic 6. Find other Visual Basic 6 articles. |
There are numerous ways to get "special" paths in windows. You can read them directly from the registry, but this is not recommended. You can also get a few select ones by reading the environment variables, but again, these are not guaranteed. The proper way is to use the SHGetSpecialFolderLocation() function.
Private Declare Function SHGetSpecialFolderLocation Lib "shell32" _ (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long Private Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, ByVal pszPath As String) As Long Private Const ERROR_SUCCESS = 0 Private Const MAX_LENGTH = 260 Public Function GetSpecialFolder(ByVal CSIDL As Long) As String Dim sPath As String Dim pidl As Long 'Get the ID list from the Path ID If SHGetSpecialFolderLocation(0, CSIDL, pidl) = ERROR_SUCCESS Then 'Allocate the space for the path sPath = Space$(MAX_LENGTH) 'Get the real path from the ID list If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then 'Strip off the trailing null characters GetSpecialFolder = Left$(sPath, InStr(sPath, Chr$(0)) - 1) 'And add a trailing \ If Right(GetSpecialFolder, 1) <> "\" Then GetSpecialFolder = GetSpecialFolder & "\" End If End If End Function
The only exception to this rule is the temporary folder. For this, you need to make use of the GetTempPath() function.
Public Function TemporaryPath() As String Dim Data As String Dim Size As Long 'Get the size needed to store the path Size = GetTempPath(0, "") 'Create a string long enough Data = String(Size, vbNullChar) 'Get the Temporary path itself GetTempPath Len(Data), Data 'And remove the trailing Null character TemporaryPath = Left(Data, Len(Data) - 1) End Function
CSIDL folder values
The values for various folders are as follows:
Folder | Constant | Value | Example |
---|---|---|---|
Documents | |||
My Documents | CSIDL_PERSONAL | &H05 | (user)\My Documents |
My Pictures | CSIDL_MYPICTURES | &H27 | (user)\My Documents\My Pictures |
My Music | CSIDL_MYMUSIC | &H0D | (user)\My Documents\My Music |
My Videos | CSIDL_MYVIDEO | &H0E | (user)\My Documents\My Videos |
Common documents | CSIDL_COMMON_DOCUMENTS | &H2E | (all users)\Documents |
Common Pictures | CSIDL_COMMON_PICTURES | &H36 | (all users)\Documents\My Pictures |
Common Music | CSIDL_COMMON_MUSIC | &H35 | (all users)\Documents\My Music |
Common Videos | CSIDL_COMMON_VIDEO | &H37 | (all users)\Documents\My Videos |
Start menu | |||
Start menu | CSIDL_STARTMENU | &H0B | (user)\Start Menu |
Programs | CSIDL_PROGRAMS | &H02 | (user)\Start Menu\Programs |
Startup | CSIDL_STARTUP | &H07 | (user)\Start Menu\Programs\Startup |
Common start menu | CSIDL_COMMON_STARTMENU | &H16 | (all users)\Start Menu |
Common programs | CSIDL_COMMON_PROGRAMS | &H17 | (all users)\Start Menu\Programs |
Common Startup | CSIDL_COMMON_STARTUP | &H18 | (all users)\Start Menu\Programs\Startup |
Shell folders | |||
Desktop | CSIDL_DESKTOPDIRECTORY | &H10 | (user)\Desktop |
Favourites | CSIDL_FAVORITES | &H06 | (user)\Favorites |
Recent documents | CSIDL_RECENT | &H08 | (user)\Recent |
Send to... | CSIDL_SENDTO | &H09 | (user)\SendTo |
Templates | CSIDL_TEMPLATES | &H15 | (user)\Templates |
Common desktop | CSIDL_COMMON_DESKTOPDIRECTORY | &H19 | (all users)\Desktop |
Common favourites | CSIDL_COMMON_FAVORITES | &H1F | (all users)\Favourites |
Common templates | CSIDL_COMMON_TEMPLATES | &H2D | (all users)\Templates |
"Data" folders | |||
Application data | CSIDL_APPDATA | &H1A | (user)\Application Data |
Local application data | CSIDL_LOCAL_APPDATA | &H1C | (user)\Local Settings\Application Data |
Common application data | CSIDL_COMMON_APPDATA | &H23 | (all users)\Application Data |
IE folders | |||
Temporary internet files | CSIDL_INTERNET_CACHE | &H20 | |
IE Cookies | CSIDL_COOKIES | &H21 | |
IE History | CSIDL_HISTORY | &H22 | |
System folders | |||
Windows directory | CSIDL_WINDOWS | &H24 | C:\Windows |
System directory | CSIDL_SYSTEM | &H25 | C:\Windows\System32 |
Fonts | CSIDL_FONTS | &H14 | C:\Windows\Fonts |
Program files | CSIDL_PROGRAM_FILES | &H26 | C:\Program Files |
Common files | CSIDL_PROGRAM_FILES_COMMON | &H2B | C:\Program Files\Common Files |
User profile | CSIDL_PROFILE | &H28 | (user) |
Admin tools | |||
Common admin tools | CSIDL_COMMON_ADMINTOOLS | &H2F | (all users)\Start Menu\Programs\Administrative Tools |
Admin tools | CSIDL_ADMINTOOLS | &H30 | {user}\Start Menu\Programs\Administrative Tools |