导航:首页 > 编程语言 > 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程序分目录相关的资料

热点内容
教编程怎么报名 浏览:810
大王卡联通哪些app免费 浏览:267
大数据时代需要学习什么 浏览:690
乐视启动安卓密码 浏览:758
本地文件如何找到酷狗下载的 浏览:898
vs源文件路径与生成系统路径 浏览:938
计算机网络技术按位与怎么算 浏览:259
lstm代码 浏览:622
耐克网站如何免费抽鞋 浏览:229
国外化妆品网站有哪些 浏览:772
excel有一个文件一保存就崩溃 浏览:382
数控r50怎么编程 浏览:509
java时间戳转换工具类 浏览:184
vb编程如何关机 浏览:323
qq接收文件默认的路径 浏览:98
深圳车模电话微信泄露 浏览:519
有道大数据 浏览:785
大数据及相关技术 浏览:735
剪切掉的文件能恢复吗 浏览:173
文件夹审计 浏览:811

友情链接