導航:首頁 > 編程語言 > 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程序分目錄相關的資料

熱點內容
動漫圖片的文件格式 瀏覽:560
黑衣緊身美女跳小蘋果 瀏覽:670
無法收縮資料庫 瀏覽:216
java中獲取二維數組的長度 瀏覽:510
手機裡面的數據線怎麼接 瀏覽:491
微信轉帳是紅包嗎 瀏覽:748
如何學會函數編程 瀏覽:985
js賦值高度 瀏覽:940
錄像機登錄密碼 瀏覽:94
中斷程序格式 瀏覽:543
微信電話本批量刪除聯系人 瀏覽:439
hp5200固件升級文件 瀏覽:176
除了問卷星還有哪裡收集數據 瀏覽:387
如何編程五子棋盤 瀏覽:747
微信相冊空間 瀏覽:839
蘋果怎麼刷回935 瀏覽:437
linux的模板文件在哪個文件夾 瀏覽:923
企業網路規劃拓撲圖 瀏覽:927
在哪裡可以下載書痴APP 瀏覽:644
橡皮擦工具怎麼使用方法 瀏覽:781

友情鏈接