chillibear.com

Windows special folders

Useful Delphi function to obtain the various special folders from the Windows operating system (2k, XP, etc). You need to pass a folder ID integer in, the various enumerations of the special folders are listed in the comment block at the top of the code (_e.g. CSIDLSTARTMENU).

function GetSpecialFolder(FolderID: Integer) : String;
{
  CSIDL_DESKTOP
  CSIDL_INTERNET
  CSIDL_PROGRAMS
  CSIDL_CONTROLS
  CSIDL_PRINTERS
  CSIDL_PERSONAL
  CSIDL_FAVORITES
  CSIDL_STARTUP
  CSIDL_RECENT
  CSIDL_SENDTO
  CSIDL_BITBUCKET
  CSIDL_STARTMENU
  CSIDL_DESKTOPDIRECTORY
  CSIDL_DRIVES
  CSIDL_NETWORK
  CSIDL_NETHOOD
  CSIDL_FONTS
  CSIDL_TEMPLATES
  CSIDL_COMMON_STARTMENU
  CSIDL_COMMON_PROGRAMS
  CSIDL_COMMON_STARTUP
  CSIDL_COMMON_DESKTOPDIRECTORY
  CSIDL_APPDATA
  CSIDL_PRINTHOOD
  CSIDL_ALTSTARTUP
  CSIDL_COMMON_ALTSTARTUP
  CSIDL_COMMON_FAVORITES
  CSIDL_INTERNET_CACHE
  CSIDL_COOKIES
  CSIDL_HISTORY
}
var
  Allocator: IMalloc
class='o'>; SpecialDir: PItemIdList; Buffer: array[0..MAX_PATH] of Char; begin if SHGetMalloc(Allocator) = NOERROR then begin SHGetSpecialFolderLocation(0, FolderID, SpecialDir); SHGetPathFromIDList(SpecialDir, @Buffer[0]); Allocator.Free(SpecialDir); Result := string(Buffer); end; end;

Written on 01 Jan 2009 and categorised in Delphi and Windows, tagged as SHGetSpecialFolderLocation

Home, Post archive

site copyright Eric Freeman

Valid XHTML 1.0 Strict