Delphi XE10 文件目錄/路徑操作 (Andorid、ios、windows)
//獲取臨時文件路徑(支持安卓、IOS)
function GeFileName(const AFileName: string): string;
begin
{$IFDEF ANDROID}
Result := TPath.GetTempPath + '/' + AFileName;
{$ELSE}
{$IFDEF IOS}
Result := TPath.GetHomePath + '/Documents/' + AFileName;
{$ELSE}
Result := AFileName;
{$ENDIF}
{$ENDIF}
end;
//引用 IOUtils.pas 文件說明
//路徑類
TPath.GetTempPath; {獲取臨時文件夾路徑}
TPath.GetTempFileName; {獲取一個臨時文件名}
TPath.GetPathRoot(); {提取盤符, 如: c:\}
TPath.GetDirectoryName(); {提取路徑}
TPath.GetFileName(); {提取文件名}
TPath.GetExtension(); {提取擴展名}
TPath.GetFileNameWithoutExtension(); {提取無擴展名的文件名}
TPath.ChangeExtension(); {更換擴展名}
TPath.DriveExists(); {檢查路徑中的驅動器是否存在}
TPath.GetFullPath(); {根據相對路徑給出全路徑}
TPath.HasExtension(); {判斷是否有擴展名}
TPath.IsPathRooted(); {判斷是否是絕對路徑}
TPath.Combine(); {結合路徑}
TPath.GetRandomFileName; {產生一個隨機文件名}
TPath.GetGUIDFileName(); {用於產生一個唯一的文件名, 布爾參數 決定名稱中是否包含 -}
TPath.IsValidPathChar(); {判斷給定的字符是否能用於路徑名}
TPath.IsValidFileNameChar(); {判斷給定的字符是否能用於文件名}
TPath.AltDirectorySeparatorChar; {Windows 下是 "\"}
TPath.AltDirectorySeparatorChar; {Windows 下是 "/"}
TPath.ExtensionSeparatorChar; {Windows 下是 "."}
TPath.PathSeparator; {Windows 下是 ";"}
TPath.VolumeSeparatorChar; {Windows 下是 ":"}
//目錄類
TDirectory.CreateDirectory(); {建立新目錄}
TDirectory.Exists(); {判斷文件夾是否存在}
TDirectory.IsEmpty(); {判斷文件夾是否為空}
TDirectory.Copy(); {復制文件夾}
TDirectory.Move(); {移動文件夾}
TDirectory.Delete(); {刪除文件夾, 第二個參數為 True 可刪除 非空文件夾}
TDirectory.GetDirectoryRoot(); {獲取目錄的根盤符, 如: C:\}
TDirectory.GetCurrentDirectory; {獲取當前目錄}
TDirectory.SetCurrentDirectory(); {設置當前目錄}
TDirectory.GetLogicalDrives; {獲取驅動器列表; 下有舉例}
TDirectory.GetAttributes(); {獲取文件夾屬性, 譬如只讀、存檔等; 下有舉例}
TDirectory.SetAttributes(); {設置文件夾屬性; 下有舉例}
//文件類
TFile.Exists();//判斷指定的文件是否存在
TFile.Copy();//復制文件
TFile.Move();//移動文件
TFile.Delete();//刪除文件
TFile.Replace();//替換文件
//Andorid、ios 常用獲取路徑方式:
function GetPicturesPath; //圖片路徑
function GetSharedPicturesPath;
function GetCameraPath; //相機路徑
function GetSharedCameraPath;
function GetMusicPath; //音樂路徑
function GetSharedMusicPath;
function GetMoviesPath; //視頻
function GetSharedMoviesPath;
function GetAlarmsPath;
function GetSharedAlarmsPath;
function GetDownloadsPath; //下載
function GetSharedDownloadsPath;
function GetRingtonesPath;
function GetSharedRingtonesPath;
Andriod 測試返回示例:
GetRandomFileName: 0q136naA.5AG GetTempFileName: /storage/emulated/0/Android/data/****/files/tmp/tmp.AADOxuXzyW GetTempPath: /storage/emulated/0/Android/data/****/files/tmp GetHomePath: /data/user/0/*****/files GetDocumentsPath: /data/user/0/*****/files GetSharedDocumentsPath: /storage/emulated/0/Documents GetLibraryPath: /data/app/*****-Qxg_gUvSDZA6j6xi6bRHtQ==/lib/arm GetCachePath: /data/user/0/*****/cache GetPublicPath: /storage/emulated/0/Android/data/*****/files GetPicturesPath: /storage/emulated/0/Android/data/*****/files/Pictures GetSharedPicturesPath: /storage/emulated/0/Pictures GetCameraPath: /storage/emulated/0/Android/data/*****/files/DCIM GetSharedCameraPath: /storage/emulated/0/DCIM GetMusicPath: /storage/emulated/0/Android/data/*****/files/Music GetSharedMusicPath: /storage/emulated/0/Music GetMoviesPath: /storage/emulated/0/Android/data/*****/files/Movies GetAlarmsPath: /storage/emulated/0/Android/data/*****/files/Alarms GetSharedAlarmsPath: /storage/emulated/0/Alarms GetDownloadsPath: /storage/emulated/0/Android/data/*****/files/Download GetSharedDownloadsPath: /storage/emulated/0/Download GetRingtonesPath: /storage/emulated/0/Android/data/*****/files/Ringtones GetSharedRingtonesPath: /storage/emulated/0/Ringtones
創建時間:2019.07.05 更新時間:2020.06.06, 07.23
