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

熱點內容
wifi網路延時大怎麼處理 瀏覽:345
雲辦公的原理是把傳統文件放哪裡 瀏覽:113
不屬於群防群治隊伍數據項有哪些 瀏覽:404
java樹向上找 瀏覽:241
資料庫查詢票價 瀏覽:503
word黑色下劃線怎麼去掉 瀏覽:879
學習編程怎麼學比較好 瀏覽:351
有什麼好看的地圖網站 瀏覽:593
oppo如何設置app黑名單 瀏覽:71
移動數據用了多少在哪裡顯示 瀏覽:549
excel表改變文件名顏色的方法 瀏覽:966
linuxshell二進制文件 瀏覽:36
什麼是網路道德問題產生的 瀏覽:836
c清除文件夾 瀏覽:407
租房貸款用什麼app 瀏覽:59
虛擬機oracle安裝教程 瀏覽:745
太原編程班哪裡有 瀏覽:544
壓縮文件怎麼找 瀏覽:586
wwwjshousecomcn 瀏覽:648
U盤文件路徑在哪 瀏覽:502

友情鏈接