2015-10-28 17 views
5

C'è un modo per sfogliare e ricorsivamente copiare/spostare tutti i file e le sottodirectory di una directory all'interno della sezione del codice? (PrepareToInstall)Inno Setup: copia cartella, sottocartelle e file in modo ricorsivo nella sezione Codice

Ho bisogno di ignorare una directory specifica, ma usando xcopy ignora tutte le directory /default/, per esempio, e ho bisogno di ignorare solo una specifica.

La sezione Files viene eseguita in un secondo momento, quando necessario.

risposta

9

Per copiare ricorsivamente una directory a livello di codice usare:

procedure DirectoryCopy(SourcePath, DestPath: string); 
var 
    FindRec: TFindRec; 
    SourceFilePath: string; 
    DestFilePath: string; 
begin 
    if FindFirst(SourcePath + '\*', FindRec) then 
    begin 
    try 
     repeat 
     if (FindRec.Name <> '.') and (FindRec.Name <> '..') then 
     begin 
      SourceFilePath := SourcePath + '\' + FindRec.Name; 
      DestFilePath := DestPath + '\' + FindRec.Name; 
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then 
      begin 
      if FileCopy(SourceFilePath, DestFilePath, False) then 
      begin 
       Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath])); 
      end 
       else 
      begin 
       Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath])); 
      end; 
      end 
      else 
      begin 
      if DirExists(DestFilePath) or CreateDir(DestFilePath) then 
      begin 
       Log(Format('Created %s', [DestFilePath])); 
       DirectoryCopy(SourceFilePath, DestFilePath); 
      end 
       else 
      begin 
       Log(Format('Failed to create %s', [DestFilePath])); 
      end; 
      end; 
     end; 
     until not FindNext(FindRec); 
    finally 
     FindClose(FindRec); 
    end; 
    end 
    else 
    begin 
    Log(Format('Failed to list %s', [SourcePath])); 
    end; 
end; 

Aggiungi alcun filtraggio è necessario. Guarda come vengono filtrati . e ...


Per un esempio di utilizzo, vedere le mie risposte alle domande:

Problemi correlati