Technology Learning

导航

删除非空目录

function   DeleteDirectory(mSource:   string):   Boolean;
var
    vSHFileOpStruct:   TSHFileOpStruct;
begin
    FillChar(vSHFileOpStruct,   SizeOf(vSHFileOpStruct),   0);
    with   vSHFileOpStruct   do
    begin
        Wnd   :=   Application.Handle;
        wFunc   :=   FO_DELETE;
        pFrom   :=   PChar(mSource   +   #0);
        pTo   :=   #0#0;
        fFlags   :=   FOF_NOCONFIRMATION+FOF_SILENT;
    end;
    Result   :=   SHFileOperation(vSHFileOpStruct)   =   0;
end;   {   DeleteDirectory   }

procedure   TForm1.Button1Click(Sender:   TObject);
begin
    DeleteDirectory( 'C:\temp ');
end;

 

 

procedure   DelDir(SourcePath:   String);
var
    sr:   TSearchRec;
begin
    SourcePath:=IncludeTrailingPathDelimiter(SourcePath);
    if   FindFirst(SourcePath   +   '*.* ',   faAnyFile,   sr)   =   0   then
    begin
        repeat
            DeleteFile(SourcePath   +   sr.Name);
        until   FindNext(sr)   <>   0;
        FindClose(sr);
        RemoveDir(SourcePath);
    end;
end;

posted on 2010-08-05 14:56  浔阳渔夫  阅读(417)  评论(1编辑  收藏  举报