delphi 刪除檔案

2021-04-30 06:27:23 字數 1313 閱讀 1202

function   tmainform.deletedirectory(nowpath:   string):   boolean;   //刪除整個目錄  

var  

search:   tsearchrec;  

ret:   integer;  

key:   string;  

begin  

if   nowpath[length(nowpath)]   <>   '/'   then  

nowpath   :=   nowpath   +   '/';  

key   :=   nowpath   +   '*.*';  

ret   :=   findfirst(key,   faanyfile,   search);  

while   ret   =   0   do   begin  

if   ((search.attr   and   fadirectory)   =   fadirectory)  

then   begin  

if   (search.name   <>   '.')   and   (search.name   <>   '..')   then  

deletedirectory(nowpath   +   search.name);  

end   else   begin  

if   ((search.attr   and   fadirectory)   <>   fadirectory)   then   begin  

deletefile(nowpath   +   search.name);  

end;  

end;  

ret   :=   findnext(search);  

end;  

findclose(search);  

removedir(nowpath);  //這個是刪除本資料夾的 

result   :=   true;  

end;

簡單的辦法:  

用tfilelistbox控制項,directory=adir,  

for   i   :=   0   to   filelistbox1.items.count   -   1   do   begin  

deletefile(pchar(filelistbox1.items[i]));  

end;  

其實就是乙個乙個刪除目錄裡的檔案,也可以自己寫**獲得目錄裡的所有檔案,  

如果有子目錄,可以用遞迴的方法刪除

Delphi 目錄及子目錄所有檔案刪除

需要引用單元 shellapi function deldirectory const source string boolean var fo tshfileopstruct begin fillchar fo,sizeof fo 0 with fo do begin wnd 0 wfunc fo...

Delphi單元檔案

1.庫單元檔案頭 其中宣告了庫單元的名字.2.inte ce部分 由保留字inte ce開始,結束於保留字implementation,它用來宣告引用的單元,常量,資料型別,變數,過程和函式.在inte ce部分宣告的變數,常量,資料型別,過程,函式都可以供外部引用,對整個程式而言是共有的.也就是說...

delphi工程檔案

一般包括以下檔案 專案檔案 dpr 專案選項檔案 dof 配置檔案 cfg 資源檔案 res 窗體檔案 dfm 單元檔案 pas 前面四個檔案與專案同名,後兩個使用單元的名字 快捷ctrl f12開啟單元檔案,專案的單元檔案內容為 program後跟專案檔名,如果該專案是乙個動態庫,則會使用liba...