Delphi XE10 文件目录/路径操作 (Andorid、ios、windows)

Delphi XE10 文件目录/路径操作 (Andorid、ios、windows)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//获取临时文件路径(支持安卓、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 常用获取路径方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 测试返回示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

 

posted on   滔Roy  阅读(3940)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报

导航

点击右上角即可分享
微信分享提示