From 4507911224e6896b32c9ce4dd91bbd9066947e7e Mon Sep 17 00:00:00 2001 From: juha Date: Mon, 30 Apr 2012 17:15:13 +0000 Subject: [PATCH] LazUtils: Improve CopyDirTree, modified from a patch from Takeda Matsuki. git-svn-id: trunk@37109 - --- components/lazutils/fileutil.inc | 16 ++++++++++------ components/lazutils/fileutil.pas | 3 +-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/components/lazutils/fileutil.inc b/components/lazutils/fileutil.inc index e4ac0f4fd2..de3e201afe 100644 --- a/components/lazutils/fileutil.inc +++ b/components/lazutils/fileutil.inc @@ -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; diff --git a/components/lazutils/fileutil.pas b/components/lazutils/fileutil.pas index f67e4dedf5..2fa06f1bea 100644 --- a/components/lazutils/fileutil.pas +++ b/components/lazutils/fileutil.pas @@ -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;