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

熱點內容
word文件夾怎麼樣可以全選 瀏覽:658
在大一編程跟不上怎麼辦 瀏覽:742
coreldraw文件如何導入3dmax 瀏覽:150
招標文件如何用word做密封頁 瀏覽:44
如何在c51中調用匯編程序 瀏覽:824
java字元串轉碼gbk 瀏覽:983
win怎麼打開隱藏文件夾選項 瀏覽:454
榮耀手機qq接收文件在哪個文件夾 瀏覽:708
messagebox的頭文件 瀏覽:100
java啟動線程處理 瀏覽:622
騰迅收藏的表情在哪個文件夾 瀏覽:388
為什麼excel的文件是word打開的 瀏覽:781
紅頭文件字體格式word 瀏覽:443
iis字體配置文件 瀏覽:285
少兒編程導師是做什麼的 瀏覽:593
當前的網路安全防禦技術有哪些 瀏覽:655
win如何重置用戶配置文件 瀏覽:178
java獲取cpu編號 瀏覽:960
qt文件指針移動 瀏覽:655
蘋果4s耳機插孔失靈 瀏覽:923

友情鏈接