Delphi 获取指定文件的驱动器名, 文件夹名, 路径名, 文件名
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
分类:
DELPHI
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本