Ver Mensaje Individual
  #1  
Antiguo 08-03-2012
petete2008 petete2008 is offline
Miembro
 
Registrado: oct 2008
Posts: 109
Reputación: 16
petete2008 Va por buen camino
copiar un directorio en otro

Hola :
Supongamos que tengo un directorio origen llamado c:\carpeta (dentro de prueba hay un subdirectorio llamado T1).
Quiero copiar el contenido de c:\carpeta (incluido ficheros y subdirectorios) a la carpeta destino c:\pp (la carpeta pp esta creada previamente manualmente).

El problema que tengo es que con el código siguiente me crea dentro de la carpeta pp otro directorio llamado carpeta y no es lo que deseo. Quiero también que se sobreescriba si algún fichero o carpeta existe dentro del directorio destino sin preguntar.

Código:
// RenameOnCollision : Boolean; //Renames if directory exists
// NoConfirmation : Boolean; //Responds "Yes to All" to any dialogs
// Silent : Boolean; //No progress dialog  is shown
// ShowProgress : Boolean; //displays progress dialog but no file names
// FromDir : String; //From directory, source
// ToDir : String // To directory, source
Function copyDir(RenameOnCollision:Boolean; NoConfirmation:Boolean; Silent:Boolean; ShowProgress:Boolean; FromDir:String; ToDir:String):Boolean;
var
  SHFileOpStruct : TSHFileOpStruct;
  FromBuf, ToBuf: Array [0..255] of Char;
begin
  Try
    Fillchar(SHFileOpStruct, Sizeof(SHFileOpStruct), 0 );
    FillChar(FromBuf, Sizeof(FromBuf), 0 );
    FillChar(ToBuf, Sizeof(ToBuf), 0 );
    StrPCopy(FromBuf, FromDir);
    StrPCopy(ToBuf, ToDir);
    With SHFileOpStruct Do
    Begin
      Wnd := 0;
      wFunc := FO_COPY;
      pFrom := @FromBuf;
      pTo := @ToBuf;
      fFlags := FOF_ALLOWUNDO;
      If RenameOnCollision Then fFlags := fFlags or
        FOF_RENAMEONCOLLISION;
      If NoConfirmation Then fFlags := fFlags or
        FOF_NOCONFIRMATION;
      If Silent Then fFlags := fFlags or
        FOF_SILENT;
      If ShowProgress Then fFlags := fFlags or
        FOF_SIMPLEPROGRESS;
    End;
  Result := (SHFileOperation(SHFileOpStruct) = 0); // it goes wrong here
  Except
    Result := False;
  End;
end;//copyDir
Código:
 copyDir( false, true, false, false, PChar('c:\prueba'), Pchar('c:\pp');
Alguien tiene idea que puede estar pasando?
gracias de antemano!!
Responder Con Cita