Pastas - copiar uma pasta inteira e suas subpastas |
Top Previous Next |
|
Don't know if this will help but here's a directory copy procedure i wrote :
procedure CopyDir (SourceDir, DestDir : String; IncludeSubDirs :Boolean = True; OverWriteFiles :Boolean = True ); { this function copies the contents of one directory into another } { by default includes sub directories and overwrites files } var SearchRec : TSearchRec; nStatus : Integer; sSourceFile, sDestinationFile : String;
begin SourceDir := AddSlashSep(SourceDir,''); DestDir := AddSlashSep(DestDir,'');
// First find all the files in the current directory nStatus := FindFirst(PChar(SourceDir+'*.*'), 0, SearchRec); while nStatus = 0 do begin ForceDirectories(DestDir); sSourceFile := SourceDir + SearchRec.Name; sDestinationFile := AddSlashSep(DestDir,ExtractFileName(SearchRec.Name)); Windows.CopyFile(PChar(sSourceFile),PChar(sDestinationFile),not OverWriteFiles); nStatus := FindNext(SearchRec); end; FindClose(SearchRec);
if IncludeSubDirs then begin // look for subfolders and search them nStatus := FindFirst(PChar(SourceDir+'*.*'), faAnyFile, SearchRec); while nStatus = 0 do begin // If it is a directory, then use recursion if ((SearchRec.Attr and faDirectory) <> 0) then begin if ( (SearchRec.Name <> '.') and (SearchRec.Name <> '..') ) then begin CopyDir( SourceDir + SearchRec.Name, DestDir+ExTractFileName(SearchRec.Name), IncludeSubDirs, OverWriteFiles); end; end; nStatus := FindNext(SearchRec) end; FindClose(SearchRec); end; end; { CopyDir }
function AddSlashSep(const aFilePath, aFileName: string): string; { Adds a backslash between path and filename if required } begin if AnsiLastChar(aFilePath)^ <> '\' then Result := aFilePath + '\' + aFileName else Result := aFilePath + aFileName; end; { AddSlashSep }
|