Navigation:  Articles > Nov-2000 >

Tip: Retrieve Folder Names

Previous pageReturn to chapter overviewNext page

Mike Gunderloy        

If you need to retrieve folder names (like the name of the Windows System folder), you have a couple of alternatives. Microsoft has provided the GetWindowsDirectory API to get the Windows directory, and GetSystemDirectory to get the Windows System directories (normally these are the C:\Windows and C:\Windows\System directory, respectively). The SHGetFolderPath API will get you the paths for folders like Favorites and My Documents.

If you've installed Office 2000, you can get all of the paths you'd ever want from the Windows Installer automation model using either Access 97 or Access 2000. To do this:

1. Set a reference in your code to the Microsoft Windows Installer Object Library.

2. Run this code:

Function GetPath(strFolderName as String) _
               As String
Dim objInstaller As WindowsInstaller.Installer
Dim objSession As WindowsInstaller.Session
Dim strGUID As String
Set objInstaller = _
objInstaller.UILevel = msiUILevelNone
strGUID = objInstaller.Products(0)
Set objSession = _
GetPath = objSession.Property(strFolderName)
End Sub

This function will hand back the path for whatever folder you request. For instance, to retrieve the path to the Documents folder for the current user (called the Application Data folder these days), you'd use:

Msgbox GetPath("AppDataFolder").

The keywords for some other folders are:

• AppDataFolder—Full path to the Application Data folder for the current user.
• CommonFilesFolder—Full path to the Common Files folder for the current user.
• DesktopFolder—Full path to the Desktop folder.
• FavoritesFolder—Full path to the Favorites folder for the current user.
• FontsFolder—Full path to the Fonts folder.
• NetHoodFolder—Full path to the NetHood folder for the current user.
• PersonalFolder—Full path to the Personal folder for the current user.
• PrintHoodFolder—Full path to the PrintHood folder for the current user.
• ProgramFilesFolder—Full path to the Program Files folder.
• ProgramMenuFolder—Full path to the Program Menu folder.
• RecentFolder—Full path to the Recent folder for the current user.
• SendToFolder—Full path to the SendTo folder for the current user.
• StartMenuFolder—Full path to the Start menu folder.
• StartupFolder—Full path to the Startup folder.
• System16Folder—Full path to the folder for 16-bit system DLLs.
• SystemFolder—Full path to the System folder.
• TempFolder—Full path to the Temp folder.
• TemplateFolder—Full path to the Template folder for the current user.
• WindowsFolder—Full path to the Windows folder.
• WindowsVolume—The volume of the Windows folder.