使用函数:
System.IOUtils.TDirectory.GetDirectoryRoot
函数定义:
class function GetDirectoryRoot(const Path: string): string; static;
说明: 传入一个指定目录,返回根目录,两者都是字符串类型
异常处理:目录无效或目录不存在
注:传入任意合法文件名,返回当前程序运行目录的根目录
示例:
begin // 取给定路径根目录.. try ShowMessage(TDirectory.GetDirectoryRoot(Edit1.Text)); except //所有可能发生的不正常情况交给异常处理 on e1: Exception do begin MessageDlg(e1.ClassName + ' : ' + e1.Message, mtError, [mbok], 0); Exit; end; end; end;