Difference between revisions of "Special folders"
From HashVB
m (Updated non folder CSIDLs) |
m (Added a few more for Vista, and a link to the official list) |
||
Line 139: | Line 139: | ||
The indented items return an invalid CSIDL on my system but apparently exist somewhere | The indented items return an invalid CSIDL on my system but apparently exist somewhere | ||
− | CSIDL_DESKTOP As Long = &H0 'Desktop | + | CSIDL_DESKTOP As Long = &H0 'Desktop virtual directory (user)\Desktop |
− | CSIDL_INTERNET As Long = &H1 'Internet | + | CSIDL_INTERNET As Long = &H1 'Internet Explorer desktop item |
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 'Recycle Bin | CSIDL_BITBUCKET As Long = &HA 'Recycle Bin | ||
− | + | CSIDL_MYDOCUMENTS As Long = &HC 'My Documents desktop item (v6) | |
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 | ||
− | CSIDL_NETHOOD As Long = &H13 '{user}\nethood | + | CSIDL_NETHOOD As Long = &H13 'My network places {user}\nethood |
CSIDL_PRINTHOOD As Long = &H1B '{user}\PrintHood | CSIDL_PRINTHOOD As Long = &H1B '{user}\PrintHood | ||
− | + | CSIDL_ALTSTARTUP As Long = &H1D 'non localized startup | |
− | + | CSIDL_COMMON_ALTSTARTUP As Long = &H1E 'non localized common startup | |
− | CSIDL_SYSTEMX86 As Long = &H29 'system folder for x86 apps (Alpha) | + | CSIDL_SYSTEMX86 As Long = &H29 'system folder for x86 apps (Alpha) |
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 'Network connections | CSIDL_CONNECTIONS As Long = &H31 'Network connections | ||
− | CSIDL_RESOURCES As Long = &H38 'C:\WINDOWS\Resources | + | CSIDL_RESOURCES As Long = &H38 'Windows resources C:\WINDOWS\Resources |
CSIDL_RESOURCES_LOCALIZED As Long = &H39 | CSIDL_RESOURCES_LOCALIZED As Long = &H39 | ||
CSIDL_COMMON_OEM_LINKS As Long = &H3A | CSIDL_COMMON_OEM_LINKS As Long = &H3A | ||
CSIDL_CDBURN_AREA As Long = &H3B '(user)\Local Settings\Application Data\Microsoft\CD Burning\ | CSIDL_CDBURN_AREA As Long = &H3B '(user)\Local Settings\Application Data\Microsoft\CD Burning\ | ||
− | + | CSIDL_COMPUTERSNEARME As Long = &H3D 'Local workgroup | |
+ | |||
+ | New for Vista: | ||
+ | CSIDL_PHOTOALBUMS As Long = &H45 'Photo albums | ||
+ | CSIDL_PLAYLISTS As Long = &H3F 'Playlists | ||
+ | CSIDL_SAMPLE_MUSIC As Long = &H40 '(user)\My Documents\My Music\Sample Music. | ||
+ | CSIDL_SAMPLE_PLAYLISTS As Long = &H41) '(user)\My Documents\My Music\Sample Playlists. | ||
+ | CSIDL_SAMPLE_PICTURES As Long = &H42) '(user)\My Documents\My Pictures\Sample Pictures. | ||
+ | CSIDL_SAMPLE_VIDEOS As Long = &H43 '(user)\My Documents\My Videos\Sample Videos. | ||
--> | --> | ||
Line 166: | Line 174: | ||
* {{API link|SHGetSpecialFolderLocation}} | * {{API link|SHGetSpecialFolderLocation}} | ||
* [http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shgetspecialfolderlocation.asp MSDN page] | * [http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/shgetspecialfolderlocation.asp MSDN page] | ||
+ | * [http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp CSIDL list on MSDN] |
Revision as of 14:46, 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 |