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

热点内容
我想在桌面新建一个文件夹 浏览:756
videojs苹果无法播放 浏览:496
vivo手机怎么桌面建文件夹 浏览:429
液压控制模块怎么编程 浏览:249
word加下划线颜色 浏览:425
g71的编程应用怎么操作 浏览:100
切换文件目录linux 浏览:286
同步压缩文件内容 浏览:866
诸城中考查询网站的密码是什么 浏览:615
怎么自动读取usb数据 浏览:944
自如app如何看户型图 浏览:511
一般程序编程对机子配置要求如何 浏览:43
拉伸实验数据出现水平是什么原因 浏览:615
完美世界怎么很多app不能看了 浏览:688
隐藏网络为什么别人可以连我不行 浏览:355
超级终端发送文件超时 浏览:24
文件多少m有什么意思 浏览:63
microsoftword2010 浏览:773
国务院通信大数据行程卡在哪里 浏览:581
打印机和电脑数据线连好怎么操作 浏览:877

友情链接