请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi获取指定文件的驱动器名,文件夹名,路径名,文件名

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
var
  fullFileName : string;

begin
  // Set up a full file name with drive and path
  fullFileName := 'C:\Program Files\Borland\Delphi7\Projects\Unit1.dcu';

  // Show the component parts of this full name
  ShowMessage('Drive = '+ExtractFileDrive (fullFileName));
  ShowMessage('Dir   = '+ExtractFileDir   (fullFileName));
  ShowMessage('Path  = '+ExtractFilePath  (fullFileName));
  ShowMessage('Name  = '+ExtractFileName  (fullFileName));
  ShowMessage('Ext   = '+ExtractFileExt   (fullFileName));
end;
Drive = C:
Dir   = C:\Program Files\Borland\Delphi7\Projects
Path  = C:\Program Files\Borland\Delphi7\Projects\
Name  = Unit1.dcu
Ext   = .dcu

//获取应程序文件的路径
ExtractFilePath(Application.ExeName);

var
  oldName, newName : string;

begin
  // Try to rename the current Unit1.dcu to Uni1.old
  oldName := 'Unit1.dcu';
  newName := ChangeFileExt(oldName, '.new');

  // Show the old and new values
  ShowMessage('Old name = '+oldName);
  ShowMessage('New name = '+newName);
end;
Old name = Unit1.dcu
New name = Unit1.new
var
  selectedFile   : string;
  drive          : char;
  path, fileName : string;

begin
  // Ask the user to select a file
  if PromptForFileName(selectedFile)
  then
  begin
    // Display this full file/path value
    ShowMessage('Selected file = '+selectedFile);

    // Split this full file/path value into its constituent parts
    ProcessPath(selectedFile, drive, path, fileName);
    ShowMessage('drive = '+drive);
    ShowMessage('path = '+path);
    ShowMessage('fileName = '+fileName);
  end;
end;
 { The user selects C:\Files\data.txt and hits OK }
   
   Selected file = C:\Files\data.txt
   drive = C
   path = \Files
   filename = data.txt

http://www.delphibasics.co.uk/index.html

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphi中DBGridEh的更新区域发布时间:2022-07-18
下一篇:
Delphi中record和packedrecord的区别发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap