首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi 2010 IOUtils 單元 (6):TPath 結構路徑處理方法與常用字元屬性完整列表

     編輯:Delphi

System.IOUtils.TPath 為靜態結構,集中所有路徑字串操作,跨平台一致,取代舊式 ExtractFilePath 等函式。

常用方法分類

功能方法
特殊路徑GetTempPath, GetTempFileName
路徑拆解GetPathRoot, GetDirectoryName, GetFileName, GetExtension, GetFileNameWithoutExtension
路徑修改ChangeExtension
驅動器檢查DriveExists
相對轉絕對GetFullPath
判斷HasExtension, IsPathRooted
路徑合併Combine (自動處理分隔符)
隨機/唯一檔名GetRandomFileName, GetGUIDFileName
字元驗證IsValidPathChar, IsValidFileNameChar

進階/較少用方法


HasValidPathChars, HasValidFileNameChars, GetExtendedPrefix, IsExtendedPrefixed,
IsUNCRooted, IsDriveRooted, IsUNCPath, MatchesPattern,
GetInvalidFileNameChars, GetInvalidPathChars,
GetAttributes, SetAttributes

唯讀字元常數屬性


AltDirectorySeparatorChar  // '\' (Windows)
DirectorySeparatorChar     // '/' (跨平台)
ExtensionSeparatorChar     // '.'
PathSeparator              // ';'
VolumeSeparatorChar        // ':'

使用範例


full := TPath.Combine(TPath.GetDirectoryName(param), 'sub\file.txt'); // 安全合併
ext := TPath.GetExtension(full); // .txt
name := TPath.GetFileNameWithoutExtension(full); // file
temp := TPath.GetTempFileName; // 如 C:\Users\xxx\AppData\Local\Temp\tmp123.tmp

優勢

  • 靜態結構,無建構開銷。
  • 跨平台 (Windows/macOS/Linux/Android/iOS) 行為一致。
  • 自動處理路徑分隔符差異。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved