Fórum Copiar arquivo #176210
20/08/2003
0
Preciso copiar alguns gigas de arquivos e gostaria de exibir o progresso da cópia, mas já temos isso no windows e como faço pra usar?
Okama
Curtir tópico
+ 0Posts
20/08/2003
Inutaishou
Gostei + 0
20/08/2003
Okama
Gostei + 0
20/08/2003
Nildo
Declare a variavel fPararCopia no Private.
Caso queira cancelar no meio, entao use
fPararCopia := True;
Coloque um TGauge no Form, e use a funcao abaixo:
function DoCopyFile(const SrcFile, DstFile: string; var progresso: TGauge): Boolean;
const
bufSize = 50000;
var
sStream,
dStream : TFileStream;
pBuf : Pointer;
cnt : Integer;
totCnt, strmSize: Int64;
begin
Result := True;
fPararCopia := False;
totCnt := 0;
try
sStream := TFileStream.Create(SrcFile, fmOpenRead or fmShareDenyWrite);
except
on E: Exception do
begin
Result := False;
Exit;
end;
end;
{ progresso.Visible := sStream.Size > ((1.5 * 1024) * 1024); // Maior que 1.5Mb}
Progresso.MinValue := 0;
Progresso.MaxValue := 100;
Progresso.Progress := 0;
strmSize := sStream.size;
try
try
dStream := TFileStream.Create(DstFile, fmCreate or fmShareExclusive);
except
on E: Exception do
begin
Result := False;
Exit;
end;
end;
try
GetMem(pBuf, bufSize);
try
cnt := sStream.Read(pBuf^, bufSize);
cnt := dStream.Write(pBuf^, cnt);
totCnt := totCnt + cnt;
while (cnt > 0) do
begin
If fPararCopia then
Break;
cnt := sStream.Read(pBuf^, bufSize);
cnt := dStream.Write(pBuf^, cnt);
totcnt := totcnt + cnt;
progresso.Progress := Round((totCnt / strmSize) * 100);
Application.ProcessMessages;
end;
finally
FreeMem(pBuf, bufSize);
end;
finally
dStream.Free;
if fPararCopia then {Se cancelar entao deleta o arquivo}
DeleteFile(PChar(DstFile));
end;
finally
sStream.Free;
end;
end;Gostei + 0
20/08/2003
Hamilton Dias
Dados: TSHFileOpStruct;
begin
FillChar(Dados,SizeOf(Dados), 0);
with Dados do
begin
wFunc := FO_COPY;
pFrom := PChar(´c:\SISTEMA\*.*´);
pTo := PChar(´C:\SISTEMA\INI\´);
fFlags:= FOF_ALLOWUNDO;
end;
SHFileOperation(Dados);
end;
Gostei + 0
20/08/2003
Nildo
Eu uso o 50000 pois é rapido e deixa o progress mais exato.
t+
Gostei + 0
20/08/2003
Okama
Abraços.
Gostei + 0
20/08/2003
Okama
Gostei + 0
20/08/2003
Nildo
Eh que quando eu fiz a necessidade era outra. Entao nao importava se o cara parasse a copia, porque quando ele parava a copia eu chamava uma outra funcao direto. Mas pode modifica-la como vc quiser. Ahh.. jah q vc ta testando ela, tem como vc tirar a diferenca de tempo de uma coisa com o CopyFile e uma com minha funcao? Ainda nao testei issu hehe
Valews!
t+
abraços
Gostei + 0
20/08/2003
Okama
Copiando um arquivo de 1.374 para o Drive A:
Start Copy with DoCopyFile: 16:03:01:229 End Copy with DoCopyFile: 16:04:34:624 Total Time: 1:33:395 Start Copy with CopyFile: 16:04:34:624 End Copy with CopyFile: 16:05:39:417 Total Time: 1:04:793
Gostei + 0
20/08/2003
Nildo
thank you
Gostei + 0
19/11/2003
Ruthenio
Gostei + 0
19/11/2003
Nildo
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)