How to Get Active Folder Information

Top  Previous  Next

There is a Windows API function that can be used to return the accurate path information for many common Windows folder. Based on the operation system you are using, a path to common documents may vary. This API call, SHGetFolderPath, ensures that you will always retrieve the correct path, regardless of operating system used.

 

Example:

PROGRAM

 

MAP

 MODULE('') !Make sure to include WIN32EXT library in your project.

  SHGetFolderPath(LONG,LONG,LONG,LONG,*CSTRING),LONG,PASCAL,RAW,NAME('SHGetFolderPathA')

 END

END

 

sPath CSTRING(512)

 

SHITEMID  GROUP,TYPE

cb    USHORT

abID  BYTE

END

 

ITEMIDLIST GROUP,TYPE

mkid LIKE(SHITEMID)

END

 

CSIDL_DESKTOP                 EQUATE(0H)  !{desktop}

CSIDL_INTERNET                EQUATE(1H)  !Internet Explorer (icon on desktop)

CSIDL_PROGRAMS                EQUATE(2H)  !Start Menu\Programs

CSIDL_CONTROLS                EQUATE(3H)  !My Computer\Control Panel

CSIDL_PRINTERS                EQUATE(4H)  !My Computer\Printers

CSIDL_PERSONAL                EQUATE(5H)  !My Documents

CSIDL_FAVORITES               EQUATE(6H)  !{user name}\Favorites

CSIDL_STARTUP                 EQUATE(7H)  !Start Menu\Programs\Startup

CSIDL_RECENT                  EQUATE(8H)  !{user name}\Recent

CSIDL_SENDTO                  EQUATE(9H)  !{user name}\SendTo

CSIDL_BITBUCKET               EQUATE(0AH) !{desktop}\Recycle Bin

CSIDL_STARTMENU               EQUATE(0BH) !{user name}\Start Menu

CSIDL_DESKTOPDIRECTORY        EQUATE(10H) !{user name}\Desktop

CSIDL_DRIVES                  EQUATE(11H) !My Computer

CSIDL_NETWORK                 EQUATE(12H) !Network Neighborhood

CSIDL_NETHOOD                 EQUATE(13H) !{user name}\nethood

CSIDL_FONTS                   EQUATE(14H) !windows\fonts

CSIDL_TEMPLATES               EQUATE(15H)

CSIDL_COMMON_STARTMENU        EQUATE(16H) !All Users\Start Menu

CSIDL_COMMON_PROGRAMS         EQUATE(17H) !All Users\Programs

CSIDL_COMMON_STARTUP          EQUATE(18H) !All Users\Startup

CSIDL_COMMON_DESKTOPDIRECTORY EQUATE(19H) !All Users\Desktop

CSIDL_APPDATA                 EQUATE(1AH) !{user name}\Application Data

CSIDL_PRINTHOOD               EQUATE(1BH) !{user name}\PrintHood

CSIDL_LOCAL_APPDATA           EQUATE(1CH) !{user name}\Local Settings\Application Data (non roaming)

CSIDL_ALTSTARTUP              EQUATE(1DH) !non localized startup

CSIDL_COMMON_ALTSTARTUP       EQUATE(1EH) !non localized common startup

CSIDL_COMMON_FAVORITES        EQUATE(1FH)

CSIDL_INTERNET_CACHE          EQUATE(20H)

CSIDL_COOKIES                 EQUATE(21H)

CSIDL_HISTORY                 EQUATE(22H)

CSIDL_COMMON_APPDATA          EQUATE(23H) !All Users\Application Data

CSIDL_WINDOWS                 EQUATE(24H) !GetWindowsDirectory()

CSIDL_SYSTEM                  EQUATE(25H) !GetSystemDirectory()

CSIDL_PROGRAM_FILES           EQUATE(26H) !C:\Program Files

CSIDL_MYPICTURES              EQUATE(27H) !C:\Program Files\My Pictures

CSIDL_PROFILE                 EQUATE(28H) !USERPROFILE

CSIDL_SYSTEMX86               EQUATE(29H) !x86 system directory on RISC

CSIDL_PROGRAM_FILESX86        EQUATE(2AH) !x86 C:\Program Files on RISC

CSIDL_PROGRAM_FILES_COMMON    EQUATE(2BH) !C:\Program Files\Common

CSIDL_PROGRAM_FILES_COMMONX86 EQUATE(2CH) !x86 Program Files\Common on RISC

CSIDL_COMMON_TEMPLATES        EQUATE(2DH) !All Users\Templates

CSIDL_COMMON_DOCUMENTS        EQUATE(2EH) !All Users\Documents

CSIDL_COMMON_ADMINTOOLS       EQUATE(2FH) !All Users\Start Menu\Programs\Administrative Tools

CSIDL_ADMINTOOLS              EQUATE(30H) !{user name}\Start Menu\Programs\Administrative Tools

 

CSIDL_FLAG_CREATE             EQUATE(8000H)  !combine with CSIDL_ value to force create on SHGetSpecialFolderLocation()

CSIDL_FLAG_DONT_VERIFY        EQUATE(4000H)  !combine with CSIDL_ value to force create on SHGetSpecialFolderLocation()

CSIDL_FLAG_MASK               EQUATE(0FF00H) !mask for all possible flag values

SHGFP_TYPE_CURRENT            EQUATE(0)      !current value for user, verify it exists

SHGFP_TYPE_DEFAULT            EQUATE(1)

 

MAX_LENGTH                    EQUATE(260)

S_OK                          EQUATE(0)

S_FALSE                       EQUATE(1)

 

 CODE

!an example of calling the above is as follows. It retrieves the "My Documents" folder

 

IF SHGetFolderPath(0{PROP:Handle}, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, sPath) = S_OK

 MESSAGE(sPath,'Path to My Documents')

END

 

IF SHGetFolderPath(0{PROP:Handle}, CSIDL_SYSTEM, 0, SHGFP_TYPE_CURRENT, sPath) = S_OK

 MESSAGE(sPath,'System Path')

END

 

See Also: PATH