SHGetSpecialFolderPath Function

Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, ByVal lpszPath As String, ByVal nFolder As Long, ByVal fCreate As Long) As Long

Platforms

Description & Usage

SHGetSpecialFolderPath retrieves the name of the path of a special folder on the system. This function only works with special folders which are physical directories on a disk. The function will fail if the special folder is a virtual folder.

Return Value

If an error occured, the function returns 0. If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

hwndOwner
A handle to the window calling the function, which will own any dialog boxes the function may create.
lpszPath
Receives a null-terminated string holding the path name of the special folder. A string at least 260 characters long must be passed as this parameter to receive the result.
nIndex
The CSIDL of the special folder to get the path of.
fCreate
If 0, do not create the special folder if it does not yet exist. If a non-zero value, create the special folder if it does not yet exist.

Example

' This code is licensed according to the terms and conditions listed here.

' Display the path of the directory used as the My Documents
' special folder.  This might not be "C:\My Documents" if the user renamed it!
Dim pathname As String  ' receives the path of My Documents
Dim retval As Long  ' return value

' Make enough room in the buffer to receive the string.
pathname = Space(260)
' Get the path name of the My Documents special folder
retval = SHGetSpecialFolderPath(Form1.hWnd, pathname, CSIDL_PERSONAL, 0)
' Remove the empty space from the string.
pathname = Left(pathname, InStr(pathname, vbNullChar) - 1)
' Display the result.
Debug.Print "The My Documents special folder is: "; pathname

See Also

SHGetFolderPath, SHGetSpecialFolderLocation

Category

Shell

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: September 26, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/shgetspecialfolderpath.html