How to copy, move or delete files windows like? The answer is simple: Let the shell do it for you! With the following function it’s an easy job!

Remember to add the unit ShellAPI to your uses-Section. Please read the section about SHFileOperation in the Delphi Online Help for possible values of the parameters op and flags. Some examples of using the procedure:

Send a file to the trashcan
FileOperation (filename,"",FO_DELETE,FOF_ALLOWUNDO);
Move a file to another directory
FileOperation (sourcefile,destination,FO_MOVE,FOF_ALLOWUNDO);
Copy a file to another directory
FileOperation (sourcefile,destination,FO_COPY,FOF_ALLOWUNDO);
procedure FileOperation (const source,
                               dest: string;
                         op, flags: Integer);
var shf: TSHFileOpStruct;
    s1, s2: string;
begin
 FillChar (shf, SizeOf (shf), #0);
 s1:= source + #0#0;
 s2:= dest + #0#0;
 shf.Wnd:= 0;
 shf.wFunc:= op;
 shf.pFrom:= PCHAR (s1);
 shf.pTo:= PCHAR (s2);
 shf.fFlags:= flags;
 SHFileOperation (shf);
end (*FileOperation*);