[轉貼]如何刪除整個子目錄

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[轉貼]如何刪除整個子目錄

文章 tim »

http://delphi.ktop.com.tw/topic.asp?topic_id=25313
http://delphi.about.com/bltip1199.htm
http://delphi.ktop.com.tw/TOPIC.ASP?TOPIC_ID=21922

代碼: 選擇全部

     
    uses ShellAPI; 
    Function DelTree(DirName : string): Boolean; 
    { 
    Completely deletes a directory regardless 
    of whether the directory is filled or has 
    subdirectories.  No confirmation is requested 
    so be careful. If the operation is successful 
    then True is returned, False otherwise 
    } 
    var 
     SHFileOpStruct : TSHFileOpStruct; 
     DirBuf         : array [0..255] of char; 
    begin 
     try 
      Fillchar(SHFileOpStruct,Sizeof(SHFileOpStruct),0); 
      FillChar(DirBuf, Sizeof(DirBuf), 0 ); 
      StrPCopy(DirBuf, DirName); 
      with SHFileOpStruct do begin 
       Wnd    := 0; 
       pFrom  := @DirBuf; 
       wFunc  := FO_DELETE; 
       fFlags := FOF_ALLOWUNDO; 
       fFlags := fFlags or FOF_NOCONFIRMATION; 
       fFlags := fFlags or FOF_SILENT; 
      end;  
       Result := (SHFileOperation(SHFileOpStruct) = 0); 
      except 
       Result := False; 
     end; 
    end; 
    // 
    // 
    // 
    // 
    // 
    // 
    { 
    //使用方式 
     
    if DelTree('c:TempDir') then 
      ShowMessage('Directory deleted!') 
    else 
      ShowMessage('Errors occured!'); 
    } 
多多留言, 整理文章, 把經驗累積下來.....
回覆文章