欢迎来到Java学习网!
设为首页 | 加入收藏
当前位置: 首页 > 编程开发 > Delphi编程 >

//另外其他目录参考如下代码~~

uses ShlObj;

function GetSysTempPath: string;
var
vBuffer: array[0..MAX_PATH] of Char;
begin
GetTempPath(MAX_PATH, vBuffer);
Result := vBuffer;
end; { GetSysTempPath }

function GetSysPath: string;
var
vBuffer: array[0..MAX_PATH] of Char;
begin
GetSystemDirectory(vBuffer, MAX_PATH);
Result := vBuffer;
end; { GetSysPath }

function GetWindowsPath: string;
var
vBuffer: array[0..MAX_PATH] of Char;
begin
GetWindowsDirectory(vBuffer, MAX_PATH);
Result := vBuffer;
end; { GetWindowsPath }

function GetSpecialFolderDir(mFolder: Integer): string;
{ 返回获取系统文件或系统目录 }
(*
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
*)
var
vItemIDList: PItemIDList;
vBuffer: array[0..MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(0, mFolder, vItemIDList);
SHGetPathFromIDList(vItemIDList, vBuffer); //转换成文件系统的路径
Result := vBuffer;
end; { GetSpecialFolderDir }

//DEMO--------------------------------------------------------------------------

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetSysTempPath);
ShowMessage(GetSysPath);
ShowMessage(GetWindowsPath);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.Lines.Add('CSIDL_DESKTOP: ' + GetSpecialFolderDir(CSIDL_DESKTOP));
Memo1.Lines.Add('CSIDL_INTERNET: ' + GetSpecialFolderDir(CSIDL_INTERNET));
Memo1.Lines.Add('CSIDL_PROGRAMS: ' + GetSpecialFolderDir(CSIDL_PROGRAMS));
Memo1.Lines.Add('CSIDL_CONTROLS: ' + GetSpecialFolderDir(CSIDL_CONTROLS));
Memo1.Lines.Add('CSIDL_PRINTERS: ' + GetSpecialFolderDir(CSIDL_PRINTERS));
Memo1.Lines.Add('CSIDL_PERSONAL: ' + GetSpecialFolderDir(CSIDL_PERSONAL));
Memo1.Lines.Add('CSIDL_FAVORITES: ' + GetSpecialFolderDir(CSIDL_FAVORITES));
Memo1.Lines.Add('CSIDL_STARTUP: ' + GetSpecialFolderDir(CSIDL_STARTUP));
Memo1.Lines.Add('CSIDL_RECENT: ' + GetSpecialFolderDir(CSIDL_RECENT));
Memo1.Lines.Add('CSIDL_SENDTO: ' + GetSpecialFolderDir(CSIDL_SENDTO));
Memo1.Lines.Add('CSIDL_BITBUCKET: ' + GetSpecialFolderDir(CSIDL_BITBUCKET));
Memo1.Lines.Add('CSIDL_STARTMENU: ' + GetSpecialFolderDir(CSIDL_STARTMENU));
Memo1.Lines.Add('CSIDL_DESKTOPDIRECTORY: ' + GetSpecialFolderDir(CSIDL_DESKTOPDIRECTORY));
Memo1.Lines.Add('CSIDL_DRIVES: ' + GetSpecialFolderDir(CSIDL_DRIVES));
Memo1.Lines.Add('CSIDL_NETWORK: ' + GetSpecialFolderDir(CSIDL_NETWORK));
Memo1.Lines.Add('CSIDL_NETHOOD: ' + GetSpecialFolderDir(CSIDL_NETHOOD));
Memo1.Lines.Add('CSIDL_FONTS: ' + GetSpecialFolderDir(CSIDL_FONTS));
Memo1.Lines.Add('CSIDL_TEMPLATES: ' + GetSpecialFolderDir(CSIDL_TEMPLATES));
Memo1.Lines.Add('CSIDL_COMMON_STARTMENU: ' + GetSpecialFolderDir(CSIDL_COMMON_STARTMENU));
Memo1.Lines.Add('CSIDL_COMMON_PROGRAMS: ' + GetSpecialFolderDir(CSIDL_COMMON_PROGRAMS));
Memo1.Lines.Add('CSIDL_COMMON_STARTUP: ' + GetSpecialFolderDir(CSIDL_COMMON_STARTUP));
Memo1.Lines.Add('CSIDL_COMMON_DESKTOPDIRECTORY: ' + GetSpecialFolderDir(CSIDL_COMMON_DESKTOPDIRECTORY));
Memo1.Lines.Add('CSIDL_APPDATA: ' + GetSpecialFolderDir(CSIDL_APPDATA));
Memo1.Lines.Add('CSIDL_PRINTHOOD: ' + GetSpecialFolderDir(CSIDL_PRINTHOOD));
Memo1.Lines.Add('CSIDL_ALTSTARTUP: ' + GetSpecialFolderDir(CSIDL_ALTSTARTUP));
Memo1.Lines.Add('CSIDL_COMMON_ALTSTARTUP: ' + GetSpecialFolderDir(CSIDL_COMMON_ALTSTARTUP));
Memo1.Lines.Add('CSIDL_COMMON_FAVORITES: ' + GetSpecialFolderDir(CSIDL_COMMON_FAVORITES));
Memo1.Lines.Add('CSIDL_INTERNET_CACHE: ' + GetSpecialFolderDir(CSIDL_INTERNET_CACHE));
Memo1.Lines.Add('CSIDL_COOKIES: ' + GetSpecialFolderDir(CSIDL_COOKIES));
Memo1.Lines.Add('CSIDL_HISTORY: ' + GetSpecialFolderDir(CSIDL_HISTORY));
end;

    相关教程
    推荐内容