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

热点内容
股票数据放哪里 浏览:576
m格式库文件 浏览:279
天际通数据服务怎么开票 浏览:430
写小说发哪个网站比较好 浏览:244
小米电视3蓝牙文件路径 浏览:111
shell读取文件值 浏览:909
文件夹路径栏消失 浏览:795
律师哪些业务不能代替大数据 浏览:952
lol哪些文件可以删除 浏览:701
汇编程序中del是什么意思 浏览:183
幼儿园免费网站模板下载 浏览:210
w619线刷教程 浏览:759
怎么培养编程思想 浏览:697
手机捆绑app的软件怎么卸载 浏览:32
vb编程器有什么用 浏览:999
excel如何分列数据与文字 浏览:884
512网络病毒 浏览:994
java调用google地图api接口 浏览:726
文件管理图片小窗 浏览:599
显卡数据怎么设置 浏览:557

友情链接