Bevor du Rückfragen hast erwarte ich, daß du den Quellcode studierts. Ich beantworte keine Fragen die man selbst erkennen kann.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
| function CompPath(FromPath, Path: String; var Count: Word): Boolean; begin PathWithBackSlash(FromPath);
Count := Length(FromPath);
if CompareText(FromPath, Copy(Path, 1, Count)) = 0 then Result := True else begin Count := 0; Result := False; end; end;
function CopyFileList(FromPath, ToPath: String; List: TStrings; ProgressBar: TProgressBar; var NoCopyCount: Word): Boolean; var c: Integer; Count: Word; NewFile, NewPath: String; begin Result := False; NoCopyCount := 0; ProgressBar.Max := List.Count - 1;
if FromPath[Length(FromPath)] <> '\' then FromPath := FromPath + '\'; if ToPath[Length(ToPath)] <> '\' then ToPath := ToPath + '\';
for c := 0 to List.Count - 1 do begin ProgressBar.Position := c;
if CompPath(FromPath, List[c], Count) then begin NewFile := List[c]; Delete(NewFile, 1, Count); NewFile := ToPath + NewFile;
NewPath := ExtractFilePath(NewFile); ForceDirectories(NewPath);
if not CopyFile(PChar(List[c]), PChar(NewFile), False) then Inc(NoCopyCount); end else begin Inc(NoCopyCount); end; end; end; |
Angesprochen wird nur die Funktion CopyFileList
FromPath und ToPath sollten klar sein.
List enthällt die Liste aller zu kopierenden Dateien inc. Pfadangabe. In der Funktion wird dann ab dem FromPath Pfad kopiert. Sieht ein Pfad der Datei also so aus:
c:\abc\def\ghi\jkl.txt und der FromPath so:
c:\abc\def\, dann wird ab
ghi\jkl.txt kopiert.
Die Liste muß bereits existieren. Dazu sehen den Tip FindFirst oben.
ProgressBar sollte auch klar sein. Wenn nicht benötigt, dann Nil.
Count gibt die Anzahl der nichtkopierten Dateien zurück.
Achso, das Fehler-Result ist noch nicht korrekt eingebaut. Also bitte kein Result aus der Funktion auswerten.