LazUtils: Improve CopyDirTree, modified from a patch from Takeda Matsuki.

git-svn-id: trunk@37109 -
This commit is contained in:
juha 2012-04-30 17:15:13 +00:00
parent afcd11631a
commit 4507911224
2 changed files with 11 additions and 8 deletions

View File

@ -1007,21 +1007,25 @@ begin
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
if not ForceDirectoriesUTF8(NewPath) then
Inc(FCopyFailedCount);
end;
function CopyDirTree(const SourceDir, TargetDir: string;
PreserveTime: boolean = False): Boolean;
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
var
Searcher: TCopyDirTree;
begin
Result:=False;
Searcher:=TCopyDirTree.Create;
try
Searcher.FFlags:=[cffCreateDestDirectory];
if PreserveTime then
Searcher.FFlags:=Searcher.FFlags+[cffPreserveTime];
// Destination directories are always created. User setting has no effect!
Flags:=Flags-[cffCreateDestDirectory];
Searcher.FFlags:=Flags;
Searcher.FCopyFailedCount:=0;
Searcher.FSourceDir:=SourceDir;
Searcher.FTargetDir:=TargetDir;

View File

@ -185,8 +185,7 @@ function CopyFile(const SrcFilename, DestFilename: string;
Flags: TCopyFileFlags=[cffOverwriteFile]): boolean;
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;
function CopyDirTree(const SourceDir, TargetDir: string; Flags: TCopyFileFlags=[]): Boolean;
// file actions
function ReadFileToString(const Filename: string): string;