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

熱點內容
r4燒錄卡不同版本 瀏覽:962
怎麼升級qq群為2000 瀏覽:347
微信己冊除的文件怎樣找回來 瀏覽:715
蘋果美國賬號共享2017 瀏覽:252
ps文件修改後打開還是原圖 瀏覽:220
燒卡機蘋果4微信qq哪裡下載 瀏覽:780
ug120找不到指定文件 瀏覽:522
cda文件怎麼轉換成mp3格式 瀏覽:702
青島hpv疫苗在哪個app預約 瀏覽:881
雙十一成交額2021數據在哪裡看 瀏覽:631
蘋果手機怎麼打開移動數據 瀏覽:637
文件掃描成圖片是彩色的嗎 瀏覽:50
編程里的comply什麼意思 瀏覽:91
電腦上面點了禁用網路怎麼改回來 瀏覽:28
javacatch執行 瀏覽:182
ps軟體文件名字 瀏覽:184
黑蘋果查找文件路徑 瀏覽:397
現在編程都有哪些語言 瀏覽:360
不用錢編輯pdf文件 瀏覽:973
c截圖源代碼 瀏覽:328

友情鏈接