| Attached Files | 2012-04-28 CopyDirTree2.patch [^] (2,137 bytes) 2012-04-28 07:13 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37052)
+++ fileutil.inc (working copy)
@@ -703,6 +703,39 @@
Result:=true;
end;
+{--------------------------------------------------------------------------------
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+---------------------------------------------------------------------------------}
+
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+var
+ ListToCopy:TStringList;
+ srcLoc, newLoc:String;
+ I, Processed:Integer;
+begin
+ Processed:=0;
+
+ try
+ ListToCopy:=FindAllFiles(DirectorySource, GetAllFilesMask, True);
+
+ for I:=0 to ListToCopy.Count-1 do
+ begin
+ srcLoc:=ListToCopy.Strings[I];
+ newLoc:=StringReplace(srcLoc, DirectorySource, DirectoryTarget, [rfReplaceAll]);
+ if not DirectoryExistsUTF8(ExtractFilePath(newLoc)) then ForceDirectoriesUTF8(ExtractFilePath(newLoc));
+ if CopyFile(srcLoc, newLoc, PreserveTime) then Processed:=Processed+1;
+ end;
+
+ if Processed=ListToCopy.Count then Result:=True
+ else Result:=False;
+
+ finally
+ ListToCopy.Free;
+ end;
+end;
+
{------------------------------------------------------------------------------
function ProgramDirectory: string;
------------------------------------------------------------------------------}
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37052)
+++ fileutil.pas (working copy)
@@ -70,6 +70,8 @@
function ForceDirectory(DirectoryName: string): boolean;
function DeleteDirectory(const DirectoryName: string;
OnlyChilds: boolean): boolean;
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
function ProgramDirectory: string;
function DirectoryIsWritable(const DirectoryName: string): boolean;
CopyDirTree-Demo.7z [^] (60,670 bytes) 2012-04-28 07:13
2012-04-29 CopyDirTree4.patch [^] (3,203 bytes) 2012-04-29 05:07 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37071)
+++ fileutil.inc (working copy)
@@ -1448,6 +1448,77 @@
{$ENDIF}
end;
+{ TCopyDirTree }
+type
+ TCopyDirTree = class(TFileSearcher)
+ private
+ FDirTarget:String;
+ FDirSource:String;
+ FPreserveTime:Boolean;
+ FIsAnyCopyFailed:Integer;
+ protected
+ procedure DoFileFound; override;
+ public
+ property DirTarget:String Read FDirTarget Write FDirTarget;
+ property DirSource:String Read FDirSource Write FDirSource;
+ property FailedToCopyCount:Integer Read FIsAnyCopyFailed;
+ property PreserveTime:Boolean Read FPreserveTime Write FPreserveTime;
+ end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoFileFound;
+ function ReplacePathAndCopyFile (const srcFile:String; DirSrc, DirTarget:String;
+ PreserveTime : boolean):Boolean;
+ var
+ newLoc:String;
+ begin
+ newLoc:=StringReplace(srcFile, DirSrc, DirTarget, [rfReplaceAll]);
+
+ if PreserveTime then
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory, cffPreserveTime]) then Result:=True
+ else Result:=False;
+ end
+ else
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory]) then Result:=True
+ else Result:=False;
+ end;
+ end;
+begin
+ if not ReplacePathAndCopyFile(FileName, FDirSource, FDirTarget,FPreserveTime) then
+ FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{--------------------------------------------------------------------------------
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+---------------------------------------------------------------------------------}
+
+function CopyDirTree(const DirectorySource: String; DirectoryTarget:String;
+ PreserveTime : boolean): Boolean;
+
+var
+ Searcher: TCopyDirTree;
+ CopyStatus:Boolean;
+begin
+ Searcher := TCopyDirTree.Create;
+
+ Searcher.DirTarget:=DirectoryTarget;
+ Searcher.DirSource:=DirectorySource;
+ Searcher.FPreserveTime:=PreserveTime;
+
+ try
+ Searcher.Search(DirectorySource, GetAllFilesMask, True);
+ finally
+ if Searcher.FailedToCopyCount > 0 then CopyStatus:=False;
+ Searcher.Free;
+ end;
+
+ Result:=CopyStatus;
+end;
+
{------------------------------------------------------------------------------
function ReadFileToString(const Filename: string): string;
------------------------------------------------------------------------------}
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37071)
+++ fileutil.pas (working copy)
@@ -69,6 +69,7 @@
function DirPathExists(const FileName: String): Boolean;
function ForceDirectory(DirectoryName: string): boolean;
function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string; PreserveTime : boolean): boolean;
function ProgramDirectory: string;
function DirectoryIsWritable(const DirectoryName: string): boolean;
2012-04-29 CopyDirTree5.patch [^] (3,226 bytes) 2012-04-29 05:28 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37071)
+++ fileutil.inc (working copy)
@@ -1448,6 +1448,79 @@
{$ENDIF}
end;
+{ TCopyDirTree }
+type
+ TCopyDirTree = class(TFileSearcher)
+ private
+ FDirTarget:String;
+ FDirSource:String;
+ FPreserveTime:Boolean;
+ FIsAnyCopyFailed:Integer;
+ protected
+ procedure DoFileFound; override;
+ public
+ property DirTarget:String Read FDirTarget Write FDirTarget;
+ property DirSource:String Read FDirSource Write FDirSource;
+ property FailedToCopyCount:Integer Read FIsAnyCopyFailed;
+ property PreserveTime:Boolean Read FPreserveTime Write FPreserveTime;
+ end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoFileFound;
+ function ReplacePathAndCopyFile (const srcFile:String; DirSrc, DirTarget:String;
+ PreserveTime : boolean):Boolean;
+ var
+ newLoc:String;
+ begin
+ newLoc:=StringReplace(srcFile, DirSrc, DirTarget, [rfReplaceAll]);
+
+ if PreserveTime then
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory, cffPreserveTime]) then Result:=True
+ else Result:=False;
+ end
+ else
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory]) then Result:=True
+ else Result:=False;
+ end;
+ end;
+begin
+ if not ReplacePathAndCopyFile(FileName, FDirSource, FDirTarget,FPreserveTime) then
+ FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{--------------------------------------------------------------------------------
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+---------------------------------------------------------------------------------}
+
+function CopyDirTree(const DirectorySource: String; DirectoryTarget:String;
+ PreserveTime : boolean): Boolean;
+
+var
+ Searcher: TCopyDirTree;
+ CopyStatus:Boolean;
+begin
+ CopyStatus:=True;
+
+ Searcher := TCopyDirTree.Create;
+
+ Searcher.DirTarget:=DirectoryTarget;
+ Searcher.DirSource:=DirectorySource;
+ Searcher.FPreserveTime:=PreserveTime;
+
+ try
+ Searcher.Search(DirectorySource, GetAllFilesMask, True);
+ finally
+ if Searcher.FailedToCopyCount > 0 then CopyStatus:=False;
+ Searcher.Free;
+ end;
+
+ Result:=CopyStatus;
+end;
+
{------------------------------------------------------------------------------
function ReadFileToString(const Filename: string): string;
------------------------------------------------------------------------------}
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37071)
+++ fileutil.pas (working copy)
@@ -69,6 +69,7 @@
function DirPathExists(const FileName: String): Boolean;
function ForceDirectory(DirectoryName: string): boolean;
function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string; PreserveTime : boolean): boolean;
function ProgramDirectory: string;
function DirectoryIsWritable(const DirectoryName: string): boolean;
2012-04-29 CopyDirTree6.patch [^] (3,532 bytes) 2012-04-29 08:42 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37071)
+++ fileutil.inc (working copy)
@@ -1448,6 +1448,90 @@
{$ENDIF}
end;
+{ TCopyDirTree }
+type
+ TCopyDirTree = class(TFileSearcher)
+ private
+ FDirTarget:String;
+ FDirSource:String;
+ FPreserveTime:Boolean;
+ FIsAnyCopyFailed:Integer;
+ protected
+ procedure DoFileFound; override;
+ procedure DoDirectoryFound; override;
+ public
+ property DirTarget:String Read FDirTarget Write FDirTarget;
+ property DirSource:String Read FDirSource Write FDirSource;
+ property FailedToCopyCount:Integer Read FIsAnyCopyFailed;
+ property PreserveTime:Boolean Read FPreserveTime Write FPreserveTime;
+ end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoFileFound;
+ function ReplacePathAndCopyFile (const srcFile:String; DirSrc, DirTarget:String;
+ PreserveTime : boolean):Boolean;
+ var
+ newLoc:String;
+ begin
+ newLoc:=StringReplace(srcFile, DirSrc, DirTarget, [rfReplaceAll]);
+
+ if PreserveTime then
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory, cffPreserveTime]) then Result:=True
+ else Result:=False;
+ end
+ else
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory]) then Result:=True
+ else Result:=False;
+ end;
+ end;
+begin
+ if not ReplacePathAndCopyFile(FileName, FDirSource, FDirTarget,FPreserveTime) then
+ FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoDirectoryFound;
+var
+ NewPath:String;
+begin
+ newPath:=StringReplace(Path, FDirSource, FDirtarget, [rfReplaceAll]);
+ if not ForceDirectoriesUTF8(newPath) then FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{--------------------------------------------------------------------------------
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+---------------------------------------------------------------------------------}
+
+function CopyDirTree(const DirectorySource: String; DirectoryTarget:String;
+ PreserveTime : boolean): Boolean;
+
+var
+ Searcher: TCopyDirTree;
+ CopyStatus:Boolean;
+begin
+ CopyStatus:=True;
+
+ Searcher := TCopyDirTree.Create;
+
+ Searcher.DirTarget:=DirectoryTarget;
+ Searcher.DirSource:=DirectorySource;
+ Searcher.FPreserveTime:=PreserveTime;
+
+ try
+ Searcher.Search(DirectorySource, GetAllFilesMask, True);
+ finally
+ if Searcher.FailedToCopyCount > 0 then CopyStatus:=False;
+ Searcher.Free;
+ end;
+
+ Result:=CopyStatus;
+end;
+
{------------------------------------------------------------------------------
function ReadFileToString(const Filename: string): string;
------------------------------------------------------------------------------}
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37071)
+++ fileutil.pas (working copy)
@@ -69,6 +69,7 @@
function DirPathExists(const FileName: String): Boolean;
function ForceDirectory(DirectoryName: string): boolean;
function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string; PreserveTime : boolean): boolean;
function ProgramDirectory: string;
function DirectoryIsWritable(const DirectoryName: string): boolean;
2012-04-29 CopyDirTree7.patch [^] (3,535 bytes) 2012-04-29 09:38 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37071)
+++ fileutil.inc (working copy)
@@ -1448,6 +1448,90 @@
{$ENDIF}
end;
+{ TCopyDirTree }
+type
+ TCopyDirTree = class(TFileSearcher)
+ private
+ FDirTarget:String;
+ FDirSource:String;
+ FPreserveTime:Boolean;
+ FIsAnyCopyFailed:Integer;
+ protected
+ procedure DoFileFound; override;
+ procedure DoDirectoryFound; override;
+ public
+ property DirTarget:String Read FDirTarget Write FDirTarget;
+ property DirSource:String Read FDirSource Write FDirSource;
+ property FailedToCopyCount:Integer Read FIsAnyCopyFailed;
+ property PreserveTime:Boolean Read FPreserveTime Write FPreserveTime;
+ end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoFileFound;
+ function ReplacePathAndCopyFile (const srcFile:String; DirSrc, DirTarget:String;
+ PreserveTime : boolean):Boolean;
+ var
+ newLoc:String;
+ begin
+ newLoc:=StringReplace(srcFile, DirSrc, DirTarget, [rfReplaceAll]);
+
+ if PreserveTime then
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory, cffPreserveTime]) then Result:=True
+ else Result:=False;
+ end
+ else
+ begin
+ if CopyFile(srcFile, newLoc, [cffCreateDestDirectory]) then Result:=True
+ else Result:=False;
+ end;
+ end;
+begin
+ if not ReplacePathAndCopyFile(FileName, FDirSource, FDirTarget,FPreserveTime) then
+ FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{ TCopyDirTree }
+
+procedure TCopyDirTree.DoDirectoryFound;
+var
+ NewPath:String;
+begin
+ newPath:=StringReplace(FileName, FDirSource, FDirtarget, [rfReplaceAll]);
+ if not ForceDirectoriesUTF8(newPath) then FIsAnyCopyFailed:=FIsAnyCopyFailed+1;
+end;
+
+{--------------------------------------------------------------------------------
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string;
+ PreserveTime : boolean): boolean;
+---------------------------------------------------------------------------------}
+
+function CopyDirTree(const DirectorySource: String; DirectoryTarget:String;
+ PreserveTime : boolean): Boolean;
+
+var
+ Searcher: TCopyDirTree;
+ CopyStatus:Boolean;
+begin
+ CopyStatus:=True;
+
+ Searcher := TCopyDirTree.Create;
+
+ Searcher.DirTarget:=DirectoryTarget;
+ Searcher.DirSource:=DirectorySource;
+ Searcher.FPreserveTime:=PreserveTime;
+
+ try
+ Searcher.Search(DirectorySource, GetAllFilesMask, True);
+ finally
+ if Searcher.FailedToCopyCount > 0 then CopyStatus:=False;
+ Searcher.Free;
+ end;
+
+ Result:=CopyStatus;
+end;
+
{------------------------------------------------------------------------------
function ReadFileToString(const Filename: string): string;
------------------------------------------------------------------------------}
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37071)
+++ fileutil.pas (working copy)
@@ -69,6 +69,7 @@
function DirPathExists(const FileName: String): Boolean;
function ForceDirectory(DirectoryName: string): boolean;
function DeleteDirectory(const DirectoryName: string; OnlyChildren: boolean): boolean;
+function CopyDirTree(const DirectorySource: string; DirectoryTarget: string; PreserveTime : boolean): boolean;
function ProgramDirectory: string;
function DirectoryIsWritable(const DirectoryName: string): boolean;
2012-04-29 CopyDirTree8.patch [^] (564 bytes) 2012-04-29 18:47 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37083)
+++ fileutil.inc (working copy)
@@ -1007,8 +1007,13 @@
end;
procedure TCopyDirTree.DoDirectoryFound;
+var
+ newPath:String;
begin
// ToDo: create destination path here instead of calling CopyFile with cffCreateDestDirectory.
+ NewPath:=StringReplace(FileName, FSourceDir, FTargetDir, []);
+ if not ForceDirectoriesUTF8(NewPath) then
+ Inc(FCopyFailedCount);
end;
function CopyDirTree(const SourceDir, TargetDir: string;
2012-04-29 CopyDirTree9.patch [^] (2,233 bytes) 2012-04-29 21:10 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37083)
+++ fileutil.inc (working copy)
@@ -1003,16 +1003,27 @@
// ToDo: make sure StringReplace works in all situations !
NewLoc:=StringReplace(FileName, FSourceDir, FTargetDir, []);
if not CopyFile(FileName, NewLoc, FFlags) then
- Inc(FCopyFailedCount);
+ Inc(FCopyFailedCount);
end;
procedure TCopyDirTree.DoDirectoryFound;
+var
+ newPath:String;
begin
// ToDo: create destination path here instead of calling CopyFile with cffCreateDestDirectory.
+ NewPath:=StringReplace(FileName, FSourceDir, FTargetDir, []);
+ if (not DirectoryExistsUTF8(NewPath)) then
+ begin
+ if (not CreateDirUTF8(NewPath)) then
+ begin
+ if (not ForceDirectoriesUTF8(NewPath)) then
+ Inc(FCopyFailedCount);
+ end;
+ end;
end;
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): Boolean;
+ PreserveTime: boolean = False; OverWrite:boolean = False): Boolean;
var
Searcher: TCopyDirTree;
begin
@@ -1020,8 +1031,10 @@
Searcher:=TCopyDirTree.Create;
try
Searcher.FFlags:=[cffCreateDestDirectory];
+ if OverWrite then
+ Searcher.FFlags:=[cffOverwriteFile, cffCreateDestDirectory];
if PreserveTime then
- Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
+ Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
Searcher.FCopyFailedCount:=0;
Searcher.FSourceDir:=SourceDir;
Searcher.FTargetDir:=TargetDir;
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37083)
+++ fileutil.pas (working copy)
@@ -186,7 +186,7 @@
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
deprecated {$IFDEF VER2_5}'use cffPreserveTime in Flags parameter instead'{$ENDIF};
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): boolean;
+ PreserveTime: boolean = False; OverWrite:boolean = False): Boolean;
// file actions
function ReadFileToString(const Filename: string): string;
2012-04-30 Another Idea CopyDirTree10 (Meet with CopyFile).patch [^] (2,767 bytes) 2012-04-30 07:02 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37083)
+++ fileutil.inc (working copy)
@@ -945,6 +945,13 @@
SrcFS: TFileStreamUTF8;
DestFS: TFileStreamUTF8;
begin
+ if (cffNoWriteFileMode) in Flags then
+ begin
+ if (cffCreateDestDirectory in Flags)
+ and (not DirectoryExistsUTF8(DestFileName))
+ and (not ForceDirectoriesUTF8(DestFileName)) then
+ Result:=False;
+ end
try
SrcFS := TFileStreamUTF8.Create(SrcFilename, fmOpenRead or fmShareDenyWrite);
try
@@ -1003,16 +1010,21 @@
// ToDo: make sure StringReplace works in all situations !
NewLoc:=StringReplace(FileName, FSourceDir, FTargetDir, []);
if not CopyFile(FileName, NewLoc, FFlags) then
- Inc(FCopyFailedCount);
+ Inc(FCopyFailedCount);
end;
procedure TCopyDirTree.DoDirectoryFound;
+var
+ newPath:String;
begin
// ToDo: create destination path here instead of calling CopyFile with cffCreateDestDirectory.
+ NewPath:=StringReplace(FileName, FSourceDir, FTargetDir, []);
+ if not CopyFile('', NewPath, [cffCreateDestDirectory, cffNoWriteFileMode]) then
+ Inc(FCopyFailedCount);
end;
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): Boolean;
+ PreserveTime: boolean = False; OverWrite:Boolean = False): Boolean;
var
Searcher: TCopyDirTree;
begin
@@ -1020,8 +1032,10 @@
Searcher:=TCopyDirTree.Create;
try
Searcher.FFlags:=[cffCreateDestDirectory];
+ if OverWrite then
+ Searcher.FFlags:=[cffOverwriteFile, cffCreateDestDirectory];
if PreserveTime then
- Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
+ Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
Searcher.FCopyFailedCount:=0;
Searcher.FSourceDir:=SourceDir;
Searcher.FTargetDir:=TargetDir;
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37083)
+++ fileutil.pas (working copy)
@@ -176,7 +176,8 @@
TCopyFileFlag = (
cffOverwriteFile,
cffCreateDestDirectory,
- cffPreserveTime
+ cffPreserveTime,
+ cffNoWriteFileMode
);
TCopyFileFlags = set of TCopyFileFlag;
@@ -186,7 +187,7 @@
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
deprecated {$IFDEF VER2_5}'use cffPreserveTime in Flags parameter instead'{$ENDIF};
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): boolean;
+ PreserveTime: boolean = False; OverWrite:Boolean = False): Boolean;
// file actions
function ReadFileToString(const Filename: string): string;
2012-04-30 Another Idea CopyDirTree10 (Meet with CopyFile)2.patch [^] (2,770 bytes) 2012-04-30 07:09 [Show Content] [Hide Content]Index: fileutil.inc
===================================================================
--- fileutil.inc (revision 37083)
+++ fileutil.inc (working copy)
@@ -945,6 +945,13 @@
SrcFS: TFileStreamUTF8;
DestFS: TFileStreamUTF8;
begin
+ if (cffNoWriteFileMode) in Flags then
+ begin
+ if (cffCreateDestDirectory in Flags)
+ and (not DirectoryExistsUTF8(DestFileName))
+ and (not ForceDirectoriesUTF8(DestFileName)) then
+ Result:=False;
+ end else
try
SrcFS := TFileStreamUTF8.Create(SrcFilename, fmOpenRead or fmShareDenyWrite);
try
@@ -1003,16 +1010,21 @@
// ToDo: make sure StringReplace works in all situations !
NewLoc:=StringReplace(FileName, FSourceDir, FTargetDir, []);
if not CopyFile(FileName, NewLoc, FFlags) then
- Inc(FCopyFailedCount);
+ Inc(FCopyFailedCount);
end;
procedure TCopyDirTree.DoDirectoryFound;
+var
+ newPath:String;
begin
// ToDo: create destination path here instead of calling CopyFile with cffCreateDestDirectory.
+ NewPath:=StringReplace(FileName, FSourceDir, FTargetDir, []);
+ if not CopyFile('', NewPath, [cffCreateDestDirectory, cffNoWriteFileMode]) then
+ Inc(FCopyFailedCount);
end;
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): Boolean;
+ PreserveTime: boolean = False; OverWrite:Boolean = False): Boolean;
var
Searcher: TCopyDirTree;
begin
@@ -1020,8 +1032,10 @@
Searcher:=TCopyDirTree.Create;
try
Searcher.FFlags:=[cffCreateDestDirectory];
+ if OverWrite then
+ Searcher.FFlags:=[cffOverwriteFile, cffCreateDestDirectory];
if PreserveTime then
- Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
+ Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
Searcher.FCopyFailedCount:=0;
Searcher.FSourceDir:=SourceDir;
Searcher.FTargetDir:=TargetDir;
Index: fileutil.pas
===================================================================
--- fileutil.pas (revision 37083)
+++ fileutil.pas (working copy)
@@ -176,7 +176,8 @@
TCopyFileFlag = (
cffOverwriteFile,
cffCreateDestDirectory,
- cffPreserveTime
+ cffPreserveTime,
+ cffNoWriteFileMode
);
TCopyFileFlags = set of TCopyFileFlag;
@@ -186,7 +187,7 @@
function CopyFile(const SrcFilename, DestFilename: string; PreserveTime: boolean): boolean;
deprecated {$IFDEF VER2_5}'use cffPreserveTime in Flags parameter instead'{$ENDIF};
function CopyDirTree(const SourceDir, TargetDir: string;
- PreserveTime: boolean = False): boolean;
+ PreserveTime: boolean = False; OverWrite:Boolean = False): Boolean;
// file actions
function ReadFileToString(const Filename: string): string;
|