本文整理自网络,侵删。
偶然从 SysUtils 里发现了几个路径相关的函数, 以前没见过, 可能是 2010 新增的:
GetLocaleDirectory();
GetLocaleFile();
LocaleDirectoryExists();
LocaleFileExists();
--------------------------------------------------------------------------------
应用测试:
--------------------------------------------------------------------------------
uses IOUtils;
procedure TForm1.FormCreate(Sender: TObject);
var
p,f: string;
b: Boolean;
begin
{设置与获取当前路径}
SetCurrentDir('C:\Temp\');
ShowMessage(GetCurrentDir); { C:\Temp }
{获取当前目录下子目录的全路径}
p := GetLocaleDirectory('ABC');
ShowMessage(p); { C:\Temp\ABC\ }
{获取当前目录下文件的全路径}
f := GetLocaleFile('X.txt');
ShowMessage(f); { C:\Temp\X.txt }
f := GetLocaleFile('ABC\X.txt');
ShowMessage(f); { C:\Temp\ABC\X.txt }
{IOUtils 下的 TPath 也有类似功能}
f := TPath.GetFullPath('X.txt');
ShowMessage(f); { C:\Temp\X.txt }
f := TPath.GetFullPath('ABC\X.txt');
ShowMessage(f); { C:\Temp\ABC\X.txt }
{判断当前文件夹下的文件或子文件夹是否存在}
b := LocaleDirectoryExists('ABC'); //这相当于: DirectoryExists(GetCurrentDir + '\ABC');
b := LocaleFileExists('X.txt'); //这相当于: FileExists(GetCurrentDir + '\X.txt');
end;
相关阅读 >>
Delphi 读取图像文件base64编码加载到image组件显示图片
Delphi windows 编程[10] - wm_lbuttondown、wm_lbuttonup 和 wm_mousemove 消息
Delphi getforegroundwindow 与 getactivewindow 的区别
Delphi 文字的高度与宽度: canvas.textextent
Delphi isipadress 非正则表达式验证ip的方法
更多相关阅读请进入《Delphi》频道 >>