获取WINDOWS特殊文件夹


const
// registry entries for special paths are kept in :
  REGSTR_PATH_SPECIAL_FOLDERS   = REGSTR_PATH_EXPLORER + '\Shell Folders';
  {$EXTERNALSYM REGSTR_PATH_SPECIAL_FOLDERS}

  CSIDL_DESKTOP                 = $0000;          // <desktop>
  {$EXTERNALSYM CSIDL_DESKTOP}
  CSIDL_INTERNET                = $0001;          // Internet Explorer (icon on desktop)
  {$EXTERNALSYM CSIDL_INTERNET}
  CSIDL_PROGRAMS                = $0002;          // Start Menu\Programs
  {$EXTERNALSYM CSIDL_PROGRAMS}
  CSIDL_CONTROLS                = $0003;          // My Computer\Control Panel
  {$EXTERNALSYM CSIDL_CONTROLS}
  CSIDL_PRINTERS                = $0004;          // My Computer\Printers
  {$EXTERNALSYM CSIDL_PRINTERS}
  CSIDL_PERSONAL                = $0005;          // My Documents
  {$EXTERNALSYM CSIDL_PERSONAL}
  CSIDL_FAVORITES               = $0006;          // <user name>\Favorites
  {$EXTERNALSYM CSIDL_FAVORITES}
  CSIDL_STARTUP                 = $0007;          // Start Menu\Programs\Startup
  {$EXTERNALSYM CSIDL_STARTUP}
  CSIDL_RECENT                  = $0008;          // <user name>\Recent
  {$EXTERNALSYM CSIDL_RECENT}
  CSIDL_SENDTO                  = $0009;          // <user name>\SendTo
  {$EXTERNALSYM CSIDL_SENDTO}
  CSIDL_BITBUCKET               = $000a;          // <desktop>\Recycle Bin
  {$EXTERNALSYM CSIDL_BITBUCKET}
  CSIDL_STARTMENU               = $000b;          // <user name>\Start Menu
  {$EXTERNALSYM CSIDL_STARTMENU}
  CSIDL_MYDOCUMENTS             = CSIDL_PERSONAL; // Personal was just a silly name for My Documents
  {$EXTERNALSYM CSIDL_MYDOCUMENTS}
  CSIDL_MYMUSIC                 = $000d;          // "My Music" folder
  {$EXTERNALSYM CSIDL_MYMUSIC}
  CSIDL_MYVIDEO                 = $000e;          // "My Videos" folder
  {$EXTERNALSYM CSIDL_MYVIDEO}
  CSIDL_DESKTOPDIRECTORY        = $0010;          // <user name>\Desktop
  {$EXTERNALSYM CSIDL_DESKTOPDIRECTORY}
  CSIDL_DRIVES                  = $0011;          // My Computer
  {$EXTERNALSYM CSIDL_DRIVES}
  CSIDL_NETWORK                 = $0012;          // Network Neighborhood (My Network Places)
  {$EXTERNALSYM CSIDL_NETWORK}
  CSIDL_NETHOOD                 = $0013;          // <user name>\nethood
  {$EXTERNALSYM CSIDL_NETHOOD}
  CSIDL_FONTS                   = $0014;          // windows\fonts
  {$EXTERNALSYM CSIDL_FONTS}
  CSIDL_TEMPLATES               = $0015;
  {$EXTERNALSYM CSIDL_TEMPLATES}
  CSIDL_COMMON_STARTMENU        = $0016;          // All Users\Start Menu
  {$EXTERNALSYM CSIDL_COMMON_STARTMENU}
  CSIDL_COMMON_PROGRAMS         = $0017;          // All Users\Start Menu\Programs
  {$EXTERNALSYM CSIDL_COMMON_PROGRAMS}
  CSIDL_COMMON_STARTUP          = $0018;          // All Users\Startup
  {$EXTERNALSYM CSIDL_COMMON_STARTUP}
  CSIDL_COMMON_DESKTOPDIRECTORY = $0019;          // All Users\Desktop
  {$EXTERNALSYM CSIDL_COMMON_DESKTOPDIRECTORY}
  CSIDL_APPDATA                 = $001a;          // <user name>\Application Data
  {$EXTERNALSYM CSIDL_APPDATA}
  CSIDL_PRINTHOOD               = $001b;          // <user name>\PrintHood
  {$EXTERNALSYM CSIDL_PRINTHOOD}
  CSIDL_LOCAL_APPDATA           = $001c;          // <user name>\Local Settings\Applicaiton Data (non roaming)
  {$EXTERNALSYM CSIDL_LOCAL_APPDATA}
  CSIDL_ALTSTARTUP              = $001d;          // non localized startup
  {$EXTERNALSYM CSIDL_ALTSTARTUP}
  CSIDL_COMMON_ALTSTARTUP       = $001e;          // non localized common startup
  {$EXTERNALSYM CSIDL_COMMON_ALTSTARTUP}
  CSIDL_COMMON_FAVORITES        = $001f;
  {$EXTERNALSYM CSIDL_COMMON_FAVORITES}
  CSIDL_INTERNET_CACHE          = $0020;  //C:\Users\Admin\AppData\Local\Microsoft\Windows\INetCache
  {$EXTERNALSYM CSIDL_INTERNET_CACHE}
  CSIDL_COOKIES                 = $0021;
  {$EXTERNALSYM CSIDL_COOKIES}
  CSIDL_HISTORY                 = $0022;
  {$EXTERNALSYM CSIDL_HISTORY}
  CSIDL_COMMON_APPDATA          = $0023;          // All Users\Application Data
  {$EXTERNALSYM CSIDL_COMMON_APPDATA}
  CSIDL_WINDOWS                 = $0024;          // GetWindowsDirectory()
  {$EXTERNALSYM CSIDL_WINDOWS}
  CSIDL_SYSTEM                  = $0025;          // GetSystemDirectory()
  {$EXTERNALSYM CSIDL_SYSTEM}
  CSIDL_PROGRAM_FILES           = $0026;          // C:\Program Files
  {$EXTERNALSYM CSIDL_PROGRAM_FILES}
  CSIDL_MYPICTURES              = $0027;          // C:\Program Files\My Pictures
  {$EXTERNALSYM CSIDL_MYPICTURES}
  CSIDL_PROFILE                 = $0028;          // USERPROFILE
  {$EXTERNALSYM CSIDL_PROFILE}
  CSIDL_SYSTEMX86               = $0029;          // x86 system directory on RISC
  {$EXTERNALSYM CSIDL_SYSTEMX86}
  CSIDL_PROGRAM_FILESX86        = $002a;          // x86 C:\Program Files on RISC
  {$EXTERNALSYM CSIDL_PROGRAM_FILESX86}
  CSIDL_PROGRAM_FILES_COMMON    = $002b;          // C:\Program Files\Common
  {$EXTERNALSYM CSIDL_PROGRAM_FILES_COMMON}
  CSIDL_PROGRAM_FILES_COMMONX86 = $002c;          // x86 Program Files\Common on RISC
  {$EXTERNALSYM CSIDL_PROGRAM_FILES_COMMONX86}
  CSIDL_COMMON_TEMPLATES        = $002d;          // All Users\Templates
  {$EXTERNALSYM CSIDL_COMMON_TEMPLATES}
  CSIDL_COMMON_DOCUMENTS        = $002e;          // All Users\Documents
  {$EXTERNALSYM CSIDL_COMMON_DOCUMENTS}
  CSIDL_COMMON_ADMINTOOLS       = $002f;          // All Users\Start Menu\Programs\Administrative Tools
  {$EXTERNALSYM CSIDL_COMMON_ADMINTOOLS}
  CSIDL_ADMINTOOLS              = $0030;          // <user name>\Start Menu\Programs\Administrative Tools
  {$EXTERNALSYM CSIDL_ADMINTOOLS}
  CSIDL_CONNECTIONS             = $0031;          // Network and Dial-up Connections
  {$EXTERNALSYM CSIDL_CONNECTIONS}
  CSIDL_COMMON_MUSIC            = $0035;          // All Users\My Music
  {$EXTERNALSYM CSIDL_COMMON_MUSIC}
  CSIDL_COMMON_PICTURES         = $0036;          // All Users\My Pictures
  {$EXTERNALSYM CSIDL_COMMON_PICTURES}
  CSIDL_COMMON_VIDEO            = $0037;          // All Users\My Video
  {$EXTERNALSYM CSIDL_COMMON_VIDEO}
  CSIDL_RESOURCES               = $0038;          // Resource Direcotry
  {$EXTERNALSYM CSIDL_RESOURCES}
  CSIDL_RESOURCES_LOCALIZED     = $0039;          // Localized Resource Direcotry
  {$EXTERNALSYM CSIDL_RESOURCES_LOCALIZED}
  CSIDL_COMMON_OEM_LINKS        = $003a;          // Links to All Users OEM specific apps
  {$EXTERNALSYM CSIDL_COMMON_OEM_LINKS}
  CSIDL_CDBURN_AREA             = $003b;          // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
  {$EXTERNALSYM CSIDL_CDBURN_AREA}
  // unused                               0x003c
  CSIDL_COMPUTERSNEARME         = $003d;          // Computers Near Me (computered from Workgroup membership)
  {$EXTERNALSYM CSIDL_COMPUTERSNEARME}
  CSIDL_FLAG_CREATE             = $8000;          // combine with CSIDL_ value to force folder creation in SHGetFolderPath()
  {$EXTERNALSYM CSIDL_FLAG_CREATE}
  CSIDL_FLAG_DONT_VERIFY        = $4000;          // combine with CSIDL_ value to return an unverified folder path
  {$EXTERNALSYM CSIDL_FLAG_DONT_VERIFY}
  CSIDL_FLAG_DONT_UNEXPAND      = $2000;          // combine with CSIDL_ value to avoid unexpanding environment variables
  {$EXTERNALSYM CSIDL_FLAG_DONT_UNEXPAND}
  CSIDL_FLAG_NO_ALIAS           = $1000;          // combine with CSIDL_ value to insure non-alias versions of the pidl
  {$EXTERNALSYM CSIDL_FLAG_NO_ALIAS}
  CSIDL_FLAG_PER_USER_INIT      = $0800;          // combine with CSIDL_ value to indicate per-user init (eg. upgrade)
  {$EXTERNALSYM CSIDL_FLAG_PER_USER_INIT}
  CSIDL_FLAG_MASK               = $FF00;          // mask for all possible flag values
  {$EXTERNALSYM CSIDL_FLAG_MASK}



uses
  Vcl.ExtActns,Winapi.ShlObj, Winapi.ActiveX, System.Win.ComObj,
  ShellApi,Winapi.Windows;


function GetSpecialFolderDir(const folderid: integer): string;
var
  pidl: pItemIDList;
  buffer: array[0..255] of char;
begin
  SHGetSpecialFolderLocation(0, folderid, pidl);
  SHGetPathFromIDList(pidl, buffer);
  Result := strpas(buffer);
end;

//C:\Users\Admin\AppData\Local\Microsoft\Windows\INetCache
procedure TForm1.Button2Click(Sender: TObject);
begin
    eDIT1.Text:=GetSpecialFolderDir( CSIDL_INTERNET_CACHE );
end;







获取WINDOWS特殊文件夹

 
获取WINDOWS特殊文件夹


unit Unit1;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
uses shlobj;
{$R *.dfm}
 
function GetSpecialFolderDir(const folderid:integer):string;
var
    pidl:pItemIDList;
    buffer:array [ 0..255 ] of char ;
begin
    SHGetSpecialFolderLocation( application.Handle , folderid, pidl);
    SHGetPathFromIDList(pidl, buffer);
    Result:=strpas(buffer);
end;
 
 
 
procedure TForm1.Button1Click(Sender: TObject);
var
  DataBaseFolder:string;
begin
     {GetSpecialFolderDir( CSIDL_PERSONAL )
    = D:\Administrator\Documents}
     {D:\Administrator\Documents\DataBase}
     DataBaseFolder:=GetSpecialFolderDir( CSIDL_PERSONAL ) + '\DataBase';
     if not DirectoryExists(DataBaseFolder) then
        if not CreateDir(DataBaseFolder) then
            Application.MessageBox('创建数据文件夹失败','错误',MB_ICONERROR);
end;
 
end.



 
 
 
打 '*'

号的为不是真正的文件系统 ,应该用作它用。

CSIDL_BITBUCKET * 回收站

CSIDL_CONTROLS * 控制面板

CSIDL_DESKTOP * 桌面

CSIDL_DESKTOPDIRECTORY 桌面目录 // 如 C:\WINDOWS\Desktop

CSIDL_DRIVES * 我的电脑

CSIDL_FONTS 字体 // 如 C:\WINDOWS\FONTS

CSIDL_NETHOOD 网上邻居目录 // 如 C:\WINDOWS\NetHood

CSIDL_NETWORK * 网上邻居

CSIDL_PERSONAL 我的文档 // 如 C:\My Documents

CSIDL_PRINTERS * 打印机

CSIDL_PROGRAMS 程序组 // 如 C:\WINDOWS\Start Menu\Programs

CSIDL_RECENT 最近文档 // 如 C:\WINDOWS\Recent

CSIDL_SENDTO 发送到 // 如 C:\WINDOWS\SentTo

CSIDL_STARTMENU 开始菜单 // 如 C:\WINDOWS\Start Menu

CSIDL_STARTUP 启动 // 如 C:\WINDOWS\ 启动

CSIDL_TEMPLATES 模版 // 如 C:\WINDOWS\ShellNew

 
 
 
 
 
 
 

上一篇:银联SDK


下一篇:npm常用功能