Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #8  
Antiguo 24-10-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
islu,

Revisa este link : http://delphi.cjcsoft.net/viewthread.php?tid=46036

En el aparecen los siguientes 5 métodos para copiar un archivo:
Código Delphi [-]
// Método-1:
Procedure FileCopy( Const sourcefilename, targetfilename: String );
Var
  S, T: TFileStream;
Begin
  S := TFileStream.Create( sourcefilename, fmOpenRead );
  try
    T := TFileStream.Create( targetfilename, fmOpenWrite or fmCreate );
    try
      T.CopyFrom(S, S.Size ) ;
    finally
      T.Free;
    end;
  finally
    S.Free;
  end;
End;
Código Delphi [-]
// Método-2:
procedure FileCopy(const FromFile, ToFile: string);
var
  FromF, ToF: file;
  NumRead, NumWritten: Word;
  Buf: array[1..2048] of Char;
begin
  AssignFile(FromF, FromFile);
  Reset(FromF, 1);        { Record size = 1 }
  AssignFile(ToF, ToFile);    { Open output file }
  Rewrite(ToF, 1);        { Record size = 1 }
  repeat
    BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
    BlockWrite(ToF, Buf, NumRead, NumWritten);
  until (NumRead = 0) or (NumWritten < NumRead);
  System.CloseFile(FromF);
  System.CloseFile(ToF);
end;
Código Delphi [-]
// Método-3:
procedure CopyFile(FromFileName, ToFileName: string);
var
  FromFile, ToFile: File;
begin
  AssignFile(FromFile, FromFileName); { Assign FromFile to FromFileName }
  AssignFile(ToFile, ToFileName);     { Assign ToFile to ToFileName }
  Reset(FromFile);                    { Open file for input }
  try
    Rewrite(ToFile);                  { Create file for output }
    try

      { copy the file an if a negative value is returned raise an exception }
      if LZCopy(TFileRec(FromFile).Handle, TFileRec(ToFile).Handle)         raise Exception.Create('Error using LZCopy')
    finally
      CloseFile(ToFile);  { Close ToFile }
    end;
  finally
    CloseFile(FromFile);  { Close FromFile }
  end;
end;
Código Delphi [-]
// Método-4:
procedure CopyFile(FromFileName, ToFileName: string);
var
  shellinfo: TSHFileOpStructA;
  Files:String;
begin
  Files:=FromFileName+#0+#0;
  with shellinfo do
  begin
    Wnd:=Self.handle;
    wFunc:=FO_COPY;
    pFrom:=PChar(Files);
    pTo:=PChar(ToFileName);
    fFlags:=FOF_NOCONFIRMATION or FOF_SILENT;
  end;
  SHFileOperation(shellinfo);
end;
Código Delphi [-]
// Método-5:
copyfile(PChar(FromFileName),PChar(ToFileName),False);
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 24-10-2012 a las 23:02:24.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
TImage no se ve en tablet newtron Gráficos 13 28-06-2012 13:38:38
Copiar un archivo en el archivo .res y utilizarlo para copiarlo GerTorresM Varios 1 14-06-2012 15:00:09
copiar un archivo de red ingabraham Varios 7 14-03-2011 23:45:30
Copiar Archivo john_mvf Varios 2 04-07-2005 20:15:07
copiar un archivo alcides Varios 4 13-05-2005 20:55:50


La franja horaria es GMT +2. Ahora son las 19:47:21.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi