Board index » delphi » DelTree command; Removing a directory containing files

DelTree command; Removing a directory containing files

Hello!

Does anyone know an easy way to rmove a directory containing files (and
perhaps subdirectories)?
I will work with network paths, if that matter. (\\srv\vol\cat\dir)

Suggestions?

------------------
//Per Skoglund

 

Re:DelTree command; Removing a directory containing files


Quote
PS wrote in message ...
>Hello!

>Does anyone know an easy way to rmove a directory containing files (and
>perhaps subdirectories)?

Build your own, it's a simple recursive function. Use FindFirst
and FindNext (and, nowadays, FindClose - read the help file!) to
enumerate all the items you need to delete.

DOS, although it could now legally order a drink in the States,
_still_ makes you roll your own for this. However, it's probably
not alone in this. I strongly suspect that in "rm -r", it's also
rm that implements it, not the OS.

Groetjes,
Maarten Wiltink

Re:DelTree command; Removing a directory containing files


Hi,

The easiest way to delete a directory is to use SHFileOperation; here is a
procedure:

  function  MyDeleteFile(s : string) : boolean;
  var
    SHFileOpStruct : TSHFileOpStruct;
  begin
    SHFileOpStruct.Wnd := 0;
    SHFileOpStruct.wFunc := FO_DELETE; // we want to delete a file...
    SHFileOpStruct.pFrom := PChar(s + #0 + #0);  //... this file ...
    SHFileOpStruct.pTo := nil;
    SHFileOpStruct.fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
    SHFileOpStruct.hNameMappings := nil;
    SHFileOpStruct.lpszProgressTitle := nil;

    Result := SHFileOperation(SHFileOpStruct) = 0; // to the Recycle Bin
  end;

Cheers,

Erik

Quote
"PS" <p.skogl...@swipnet.se> wrote in message

news:Cv%U8.4333$t4.11155@nntpserver.swip.net...
Quote
> Hello!

> Does anyone know an easy way to rmove a directory containing files (and
> perhaps subdirectories)?
> I will work with network paths, if that matter. (\\srv\vol\cat\dir)

> Suggestions?

> ------------------
> //Per Skoglund

Other Threads