获取文件路径

  1. (* 
  2. 相对路径和绝对路径的转换 
  3. *)  
  4.   
  5.   
  6. unit xPath;  
  7.   
  8.   
  9. interface  
  10.   uses ShlwApi, Windows, SysUtils;  
  11.   
  12.   
  13. /// <summary>  
  14. /// 取绝对路径的函数。需要引用 ShlwApi.pas  
  15. /// </summary>  
  16. /// <param name="BasePath">参考路径</param>  
  17. /// <param name="RelativePath">相对路径</param>  
  18. /// <code>  
  19. /// S := GetAbsolutePath('C:\Windows\System32', '..\DEMO.TXT')  
  20. //  S 将得到 'C:\Windows\DEMO.TXT  
  21. /// </code>  
  22. function GetAbsolutePathEx(BasePath, RelativePath:string):string;  
  23.   
  24.   
  25. /// <summary>  
  26. /// 取得本身程序的路径  
  27. /// </summary>  
  28. function AppPath : string;  
  29. function GetRelativePath(const Path, AFile: string): string;  
  30.   
  31.   
  32. implementation  
  33. function GetAbsolutePathEx(BasePath, RelativePath:string):string;  
  34. var  
  35.    Dest:array [0..MAX_PATH] of char;  
  36. begin  
  37.    FillChar(Dest,MAX_PATH+1,0);  
  38.    PathCombine(Dest,PChar(BasePath), PChar(RelativePath));  
  39.    Result:=string(Dest);  
  40. end;  
  41.   
  42.   
  43. function GetRelativePath(const Path, AFile: string): string;  
  44.   function GetAttr(IsDir: Boolean): DWORD;  
  45.   begin  
  46.        if IsDir then  
  47.          Result := FILE_ATTRIBUTE_DIRECTORY  
  48.        else  
  49.          Result := FILE_ATTRIBUTE_NORMAL;  
  50.   end;  
  51. var  
  52.    p: array[0..MAX_PATH] of Char;  
  53. begin  
  54.    PathRelativePathTo(p, PChar(Path), GetAttr(False), PChar(AFile), GetAttr(True));  
  55.    Result := StrPas(p);  
  56. end;  
  57.   
  58.   
  59.   
  60.   
  61.   
  62.   
  63. function AppPath : string;  
  64. begin  
  65.   Result := extractFilePath(Paramstr(0));  
  66. end;  
  67. end.  
  68.   
  69.   
  70.   
  71.   
  72.   
  73.   
  74. (* 
  75. ExpandFileName() 返回文件的全路径(含驱动器、路径) 
  76. ExtractFileExt() 从文件名中抽取扩展名 
  77. ExtractFileName() 从文件名中抽取不含路径的文件名 
  78. ExtractFilePath() 从文件名中抽取路径名 
  79. ExtractFileDir() 从文件名中抽取目录名 
  80. ExtractFileDrive() 从文件名中抽取驱动器名 
  81. ChangeFileExt() 改变文件的扩展名 
  82. ExpandUNCFileName() 返回含有网络驱动器的文件全路径 
  83. ExtractRelativePath() 从文件名中抽取相对路径信息 
  84. ExtractShortPathName() 把文件名转化为DOS的8·3格式 
  85. MatchesMask() 检查文件是否与指定的文件名格式匹配 
  86. ExtractFilePath(FileName:String) 
  87. 该函数返回路径名,其结尾字符总是“\” 
  88.  
  89.  
  90. ExtractFileDir(FileName:String) 
  91.  
  92.  
  93. *)  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值