1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
procedure GetFilenames(Path: string ; Dest: TStrings);
var
SR: TSearchRec;
begin
if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
repeat
Dest.Add(SR.Name);
until FindNext(SR) <> 0;
FindClose(SR);
end;
Procedure CopyFiles(From , Dest:String);
var
F : TShFileOpStruct;
begin
F.Wnd := 0;
F.wFunc := FO_COPY;
F.pFrom := PCHAR(From);
F.pTo := PCHAR(Dest);
F.fFlags := FOF_ALLOWUNDO or FOF_RENAMEONCOLLISION;
if ShFileOperation(F) <> 0 then ShowMessage('Copy Failed');
end;
function ConnectShare(Drive, RemotePath, UserName, Password : String):Integer;
var
NRW : TNetResource;
begin
with NRW do
begin
dwType := RESOURCETYPE_ANY;
if Drive <> '' then
lpLocalName := PChar(Drive)
else
lpLocalName := nil;
lpRemoteName := PChar(RemotePath);
lpProvider := '';
end;
Result := WNetAddConnection2(NRW, PChar(Password), PChar(UserName), 0);
end;
function DisconnectShare(Drive : String):Integer;
begin
Result := WNetCancelConnection2(PChar(Drive), 0, false);
end;
procedure TForm1.AdvGlowButton1Click(Sender: TObject);
var A,B,C,Y:string;
begin
ConnectShare('X:','\\*.*.*.*\*.*.*.*\','Administrateur','*******');
IniFile := TIniFile.Create('myapp.ini') ;
iniFile := TIniFile.Create(ChangeFileExt(Application.ExeName,'.ini')) ;
A := IniFile.ReadString('Config','FromPath','');
B := IniFile.ReadString('Config','FromPath2','');
C := IniFile.ReadString('Config','FromPath3','');
Y := IniFile.ReadString('Config','ToPath','');
IniFile.Free;
progressbar1.Visible:=true;
progressbar1.position := 0;
progressbar1.Min := 0;
progressbar1.Max := A.Length;
Progressbar1.Enabled := True;
CopyFiles(A,Y);
progressbar1.Position := A.Length;
progressbar1.Position := 10;
progressbar1.Position := 20;
CopyFiles(B,Y);
progressbar1.Position := B.Length;
progressbar1.Position := 30;
progressbar1.Position := 40;
CopyFiles(C,Y);
progressbar1.Position := C.Length;
progressbar1.Position := 60;
//CopyFiles('I:\test\*.jpg'#0'I:\test\*.pdf'#0'I:\test\*.xls'#0, 'I:\test2');
//CopyFileWithProgressBar1('I:\test\1.jpg', 'I:\test2\1.jpg');
//Memo1.Lines.Add(B+' '+ 'Copié');
//Memo1.Lines.Add(C+' '+ 'Copié');
GetFilenames(A, ListBox1.Items);
GetFilenames(B, ListBox1.Items);
GetFilenames(C, ListBox1.Items);
Label1.Caption:='La copie a été effectué avec succes';
MessageDlg('Copie De Fichiers Terminé avec Success',mtCustom,[mbOK,mbClose], 0);
DisconnectShare('X:');
end;
procedure TForm1.AdvGlowButton2Click(Sender: TObject);
begin
Application.Terminate;
end; |
Partager