获取 Windows 特殊文件夹函数

在网上找不到比较全的,干脆自己做,现贡献出来。

unit Utils;

interface

uses
  Windows, SysUtils, ShlObj;

type
  TSpecialFolder = (
    sfDesktop,                // <desktop>
    sfInternet,               // Internet Explorer (icon on desktop)
    sfPrograms,               // Start Menu/Programs
    sfControls,               // My Computer/Control Panel
    sfPrinters,               // My Computer/Printers
    sfPersonal,               // My Documents
    sfFavorites,              // <user name>/Favorites
    sfStartup,                // Start Menu/Programs/Startup
    sfRecent,                 // <user name>/Recent
    sfSendTo,                 // <user name>/SendTo
    sfBitBucket,              // <desktop>/Recycle Bin
    sfStartMenu,              // <user name>/Start Menu
    sfMyDocuments,            // logical "My Documents" desktop icon
    sfMyMusic,                // "My Music" folder
    sfMyVideo,                // "My Videos" folder
    sfDesktopDirectory,       // <user name>/Desktop
    sfDrives,                 // My Computer
    sfNetwork,                // Network Neighborhood (My Network Places)
    sfNethood,                // <user name>/nethood
    sfFonts,                  // windows/fonts
    sfTemplates,              // <user name>/Templates
    sfCommonStartMenu,        // All Users/Start Menu
    sfCommonPrograms,         // All Users/Start Menu/Programs
    sfCommonStartup,          // All Users/Startup
    sfCommonDesktopDirectory, // All Users/Desktop
    sfAppData,                // <user name>/Application Data
    sfPrinthood,              // <user name>/PrintHood
    sfLocalAppData,           // <user name>/Local Settings/Applicaiton Data (non roaming)
    sfALTStartup,             // non localized startup
    sfCommonALTStartup,       // non localized common startup
    sfCommonFavorites,        // All Users/Favorites
    sfInternetCache,          // <user name>/Local Settings/Temporary Internet Files
    sfCookies,                // <user name>/Cookies
    sfHistory,                // <user name>/Local Settings/History
    sfCommonAppData,          // All Users/Application Data
    sfWindows,                // GetWindowsDirectory()
    sfSystem,                 // GetSystemDirectory()
    sfProgramFiles,           // C:/Program Files
    sfMyPictures,             // C:/Program Files/My Pictures
    sfProfile,                // USERPROFILE
    sfSystemX86,              // x86 system directory on RISC
    sfProgramFilesX86,        // x86 C:/Program Files on RISC
    sfProgramFilesCommon,     // C:/Program Files/Common
    sfProgramFilesCommonX86,  // x86 Program Files/Common on RISC
    sfCommonTemplates,        // All Users/Templates
    sfCommonDocuments,        // All Users/Documents
    sfCommonAdminTools,       // All Users/Start Menu/Programs/Administrative Tools
    sfAdminTools,             // <user name>/Start Menu/Programs/Administrative Tools
    sfConnections,            // Network and Dial-up Connections
    sfCommonMusic,            // All Users/My Music
    sfCommonPictures,         // All Users/My Pictures
    sfCommonVideo,            // All Users/My Video
    sfResources,              // Resource Direcotry
    sfResourcesLocalized,     // Localized Resource Direcotry
    sfCommonOEMLinks,         // Links to All Users OEM specific apps
    sfCDBurnArea,             // USERPROFILE/Local Settings/Application Data/Microsoft/CD Burning
    sfComputersNearMe         // Computers Near Me (computered from Workgroup membership)
  );

function GetSpecialFolder(SpecialFolder: TSpecialFolder): string;

implementation

function GetSpecialFolder(SpecialFolder: TSpecialFolder): string;

const
  SpecialFolderValues: array[TSpecialFolder] of Integer = ($0000, $0001, $0002,
    $0003, $0004, $0005, $0006, $0007, $0008, $0009, $000a, $000b, $000c, $000d,
    $000e, $0010, $0011, $0012, $0013, $0014, $0015, $0016, $0017, $0018, $0019,
    $001a, $001b, $001c, $001d, $001e, $001f, $0020, $0021, $0022, $0023, $0024,
    $0025, $0026, $0027, $0028, $0029, $002a, $002b, $002c, $002d, $002e, $002f,
    $0030, $0031, $0035, $0036, $0037, $0038, $0039, $003a, $003b, $003d);

var
  ItemIDList: PItemIDList;
  Buffer: array [0..MAX_PATH] of Char;
begin
  SHGetSpecialFolderLocation(0, SpecialFolderValues[SpecialFolder], ItemIDList);
  SHGetPathFromIDList(ItemIDList, Buffer);
  Result := StrPas(Buffer);
end;

end.

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

BeyondStudio

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值