Copier, déplacer, effacer plusieurs fichiers à la fois

uses
Windows, ShellAPI, Forms, Classes,SysUtils

...

function FileListToStr ( FileList: TStringList ): string;
var
i :integer;

begin
Result:= '';
for i:= FileList.Count -1 downto 0 do
begin
if FileExists(FileList.Strings[i]) then
Result:= Result + FileList.Strings[i] + #0;
end;
Result:= Result + #0#0;
end;

function DeleteFileList ( Files:string) : integer;
var
SHFileOp: TSHFileOpStruct;
begin
result:= 0;
FillChar (SHFileOp, SizeOf (SHFileOp), 0);
with SHFileOp do
begin
wFunc := FO_DELETE; // function
pFrom := PChar(Files); // file list
fFlags := 0; // flags
lpszProgressTitle:= PChar('Delete Files'); //Title
end;
Result:= SHFileOperation (SHFileOp);
end;

function RecycleFileList( Files: string) : integer;
var
SHFileOp: TSHFileOpStruct;
begin
result:= 0;
FillChar (SHFileOp, SizeOf (SHFileOp), 0);
with SHFileOp do
begin
wFunc := FO_DELETE; // function
pFrom := PChar(Files); // file list
fFlags := FOF_ALLOWUNDO; // flags
lpszProgressTitle:= PChar('Send Files To Recycle Bin'); //Title
end;
Result:= SHFileOperation (SHFileOp);
end;

function MoveFileList ( Files: string; DestDir:string): integer;
var
SHFileOp: TSHFileOpStruct;
begin
result:= 0;
FillChar (SHFileOp, SizeOf (SHFileOp), 0);
with SHFileOp do
begin
wFunc := FO_MOVE; // function
pFrom := PChar(Files); // file list
pTo := PChar(DestDir); // destination directory
fFlags := 0; // flags
lpszProgressTitle:= PChar('Move Files To '+ DestDir ); //Title
end;
Result:= SHFileOperation (SHFileOp);
end;

function CopyFileList ( Files: string; DestDir:string): integer;
var
SHFileOp: TSHFileOpStruct;
begin
result:= 0;
FillChar (SHFileOp, SizeOf (SHFileOp), 0);
with SHFileOp do
begin
wFunc := FO_COPY; // function
pFrom := PChar(Files); // file list
pTo := PChar(DestDir);
fFlags := 0; // flags
lpszProgressTitle:= PChar('Copy Files To '+ DestDir ); //Title
end;
Result:= SHFileOperation (SHFileOp);
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour19/09/2004
VisualisationVu 1746 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Fichier
Auteur de l'article
Communauté Delphi Communauté Delphi
connecté le 02/11/2011
0 articles dans la section
Contacter l'auteur