【轉】相對路徑和絕對路徑的轉換

來源:互聯網
上載者:User

標籤:use   util   absolute   max   normal   begin   驅動   fill   function   

unit xPath;    interface    uses ShlwApi, Windows, SysUtils;    /// <summary>  /// 取絕對路徑的函數。需要引用 ShlwApi.pas  /// </summary>  /// <param name="BasePath">參考路徑</param>  /// <param name="RelativePath">相對路徑</param>  /// <code>  /// S := GetAbsolutePath(‘C:\Windows\System32‘, ‘..\DEMO.TXT‘)  //  S 將得到 ‘C:\Windows\DEMO.TXT  /// </code>  function GetAbsolutePathEx(BasePath, RelativePath:string):string;      /// <summary>  /// 取得本身程式的路徑  /// </summary>  function AppPath : string;  function GetRelativePath(const Path, AFile: string): string;      implementation  function GetAbsolutePathEx(BasePath, RelativePath:string):string;  var     Dest:array [0..MAX_PATH] of char;  begin     FillChar(Dest,MAX_PATH+1,0);     PathCombine(Dest,PChar(BasePath), PChar(RelativePath));     Result:=string(Dest);  end;    function GetRelativePath(const Path, AFile: string): string;    function GetAttr(IsDir: Boolean): DWORD;    begin         if IsDir then           Result := FILE_ATTRIBUTE_DIRECTORY         else           Result := FILE_ATTRIBUTE_NORMAL;    end;  var     p: array[0..MAX_PATH] of Char;  begin     PathRelativePathTo(p, PChar(Path), GetAttr(False), PChar(AFile), GetAttr(True));     Result := StrPas(p);  end;  function AppPath : string;  begin    Result := extractFilePath(Paramstr(0));  end;  end.  {ExpandFileName() 返迴文件的全路徑(含磁碟機、路徑) ExtractFileExt() 從檔案名稱中抽取副檔名 ExtractFileName() 從檔案名稱中抽取不含路徑的檔案名稱 ExtractFilePath() 從檔案名稱中抽取路徑名 ExtractFileDir() 從檔案名稱中抽取目錄名 ExtractFileDrive() 從檔案名稱中抽取磁碟機名 ChangeFileExt() 改變檔案的副檔名 ExpandUNCFileName() 返回含有網路磁碟機的檔案全路徑 ExtractRelativePath() 從檔案名稱中抽取相對路徑資訊 ExtractShortPathName() 把檔案名稱轉化為DOS的8·3格式 MatchesMask() 檢查檔案是否與指定的檔案名稱格式匹配 ExtractFilePath(FileName:String) 該函數返迴路徑名,其結尾字元總是“\”  ExtractFileDir(FileName:String) }

 

【轉】相對路徑和絕對路徑的轉換

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.