打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
DELPHI得到文件路径的方法 .

DELPHI得到文件路径的方法 .

时间:2011-07-27 12:09:40  来源:  作者:

DELPHI得到文件路径的方法

方法一:只能到文件夹

uses FileCtrl;{记得要先引用这个}

var
  Dir: string;
begin
  SelectDirectory('选择你要 XXOO 的目录', '', Dir);
  ShowMessage('你选择了这个目录来 XXOO '+ Dir);
end;


方法二:
用opendialog,和savedialog的filename可以得到.
var
    path_name:string;//带文件名的路径
begin
    if   opendialog1.execute   then
        path_name:=opendialog1.filename;
end;  
//------------------------------------------------

if   opendialog1.execute   then
begin
//获得打开文件的路径
    filepath   :=   extractfilepath(opendialog1.filename);
//其他你的代码

end;

if   savedialog1.execute   then
begin
//获得保存文件的路径
    filepath   :=   extractfilepath(opendialog1.filename);
//其他你的代码
end;

------------------------------------------------------------------


都知道用ExtractFilePath来提取Exe文件的全部路径。

而ExtractFileDir与ExtractFilePath的区别就是少一个‘/’

嘿嘿,如ExtractFilePath( 'C:/TEST/MYPROG.EXE ')得到的就是C:/TEST/

ExtractFileDir( 'C:/TEST/MYPROG.EXE ')得到的就是C:/TEST

以上是题外话……   ^_^

可能大家都用这个:

ExtractFilePath(Application.ExeName)

来提取可执行文件的路径。

但是用Application就得Uses   Forms……

最近正好发现一招。用ParamStr(0)

delphi帮助上如下写:

ParamStr(0)   returns   the   path   and   file   name   of   the   executing   program   (for   example,   C:/TEST/MYPROG.EXE).

ExtractFilePath(ParamStr(0))与ExtractFilePath(Application.ExeName)等价。

而且在system.pas定义的。

而且里面如下操作的:

if   Index   =   0   then
    SetString(Result,   Buffer,   GetModuleFileName(0,   Buffer,   SizeOf(Buffer)))

哦,使用的是GetModuleFileName这个Api函数。

好了,到此为止继续查看Msdn有关GetModuleFileName之后。我明白并写下如下:

因为system.pas不用uses任何文件,得到exe文件所在路径ExtractFilePath(ParamStr(0))

以及Api函数GetModuleFileName的一些东西。。。。。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Delphi XE的firemonkey获取当前文件所在路径的方法
创建文件夹和复制文件到指定目录
firemonkey获取当前文件所在路径的方法
用Delphi编制可自动升级程序
Delphi编程:用流来读取TXT文件中的数据
Tidftp实现自动更新程序
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服