导航:首页 > 编程语言 > delphi程序分目录

delphi程序分目录

发布时间:2024-07-03 02:36:31

1. delphi 获取根目录下的文件名及子目录下的文件名

给一个通用过程,直接调用,运行看是不是你想要的效果。
procereGetChildFileList(AStrings:TStrings;ASourFile,
FileName:string);//查找子目录
//AStrings存放路径,ASourceFile要查找的目录,FileName搜索的文件类型若指定类型,则'*.jpg'or'*.png'
var
sour_path,sour_file:string;
TmpList:TStringList;
FileRec,subFileRec:TSearchrec;
i:Integer;
begin
if(ASourFile,Length(ASourFile),1)<>''then
sour_path:=IncludeTrailingPathDelimiter(Trim(ASourFile))//在路径后面加上反斜杠
else
sour_path:=trim(ASourFile);
sour_file:=FileName;

ifnotDirectoryExists(sour_path)then
begin
AStrings.Clear;
exit;
end;
TmpList:=TStringList.Create;
TmpList.Clear;

ifFindFirst(sour_path+'*.*',faAnyfile,FileRec)=0then
repeat
if((FileRec.AttrandfaDirectory)<>0)then
begin
if((FileRec.Name<>'.')and(FileRec.Name<>'..'))then
GetChildFileList(AStrings,sour_path+FileRec.Name+'',sour_file);
end;
untilFindNext(FileRec)<>0;
FindClose(FileRec);

ifFindFirst(sour_path+FileName,faAnyfile,subFileRec)=0then
repeat
if((subFileRec.AttrandfaDirectory)=0)then
TmpList.Add(sour_path+subFileRec.Name);
untilFindNext(subFileRec)<>0;
FindClose(subFileRec);

fori:=0toTmpList.Count-1do
AStrings.Add(TmpList.Strings[i]);
TmpList.Free;
end;

调用:
procereTForm2.SpeedButton5Click(Sender:TObject);
begin
GetChildFileList(ListBox1.Items,'D:Wyp','*.jpg');//目录自己定
GetChildFileList(ListBox1.Items,'D:Wyp','*.png');
end;

这里是将查找的目录存放在ListBox里的。

在加载List时,由于Item太多,所以有一定的延时,而不是卡死。

希望能帮到你。

2. delphi 如何创建文件夹

forcedirectories和CreateDirectory都能创建文件 ForceDirectories可以创建多层目录. 如果你创建一个目录为c:\mymusic\music 如果你的C盘不存在一个叫mymusic的文件夹 的话程序会自动创建,函数执行的结果是, 创建了两个文件夹,mymusic和music,music为 mymusic的子文件夹. CreateDirectory只能创建一个文件夹,如果 mymusic不存在,则反回创建music文件夹失败! procere TMain.WriteVPTXT(str:string);varMytextFile : TextFile; tempstr : string; SysTime: TsystemTime;begintryGetLocalTime(SysTime); //AssignFile(MyTextFile,'D:\delphi\delphitest\time.ini'); if not DirectoryExists('D:\Test') then CreateDirectory('D:\Test',nil); //创建单个目录 // forcedirectories ('D:\Test'); //创建多层目录 tempstr:='D:\Test\'+inttostr(Systime.wYear)+inttostr(systime.wMonth)+inttostr(systime.wDay)+'.txt'; AssignFile(MyTextFile,tempstr); if not fileExists(tempstr) then ReWrite(MyTextFile) else Append(MyTextFile);

阅读全文

与delphi程序分目录相关的资料

热点内容
文件夹选项没有文件类型 浏览:566
一加传入的文件找不到 浏览:478
使用动态存储分配编写完整的程序 浏览:359
com与vb6分布式应用程序设计 浏览:939
系统分页文件可以缩小吗 浏览:791
音乐网站设计源码 浏览:363
javamail服务器 浏览:853
如何把手机数据变快 浏览:589
angularjs2时间 浏览:920
下载临时文件夹找不到 浏览:592
施乐cm215固件升级 浏览:688
word2010页码左右设置 浏览:907
tpg文件 浏览:517
edusoho安装教程 浏览:251
编程猫如何申请退课 浏览:794
红米怎么用文件管理下载qq视频 浏览:560
自己要解压的文件找不到怎么办 浏览:296
文件管理的图片可以搜回来吗 浏览:369
mini下载的文件在哪里 浏览:973
mfrc522射频识别参考程序注释new 浏览:363

友情链接