From 17ca6179680c5b079f253cdd4642b3aab8c2cb3f Mon Sep 17 00:00:00 2001 From: ngleader Date: Thu, 8 Jan 2009 02:45:41 +0000 Subject: [PATCH] add method FileHandler::copyDir git-svn-id: http://xe-core.googlecode.com/svn/sandbox@5277 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/file/FileHandler.class.php | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/classes/file/FileHandler.class.php b/classes/file/FileHandler.class.php index 69d41c548..e0d4dd988 100644 --- a/classes/file/FileHandler.class.php +++ b/classes/file/FileHandler.class.php @@ -18,6 +18,39 @@ return $source; } + + + /** + * @brief 특정 디렉토리를 복사 + **/ + function copyDir($source_dir, $target_dir, $filter=null,$type=null){ + $source_dir = FileHandler::getRealPath($source_dir); + $target_dir = FileHandler::getRealPath($target_dir); + if(!is_dir($source_dir)) return false; + + // target이 없을땐 생성 + if(!file_exists($target_dir)) FileHandler::makeDir($target_dir); + + if(substr($source_dir, -1) != '/') $source_dir .= '/'; + if(substr($target_dir, -1) != '/') $target_dir .= '/'; + + $oDir = dir($source_dir); + while($file = $oDir->read()) { + if(substr($file,0,1)=='.') continue; + if($filter && preg_match($filter, $file)) continue; + if(is_dir($source_dir.$file)){ + FileHandler::copyDir($source_dir.$file,$target_dir.$file,$type); + }else{ + if($type == 'force'){ + @unlink($target_dir.$file); + }else{ + if(!file_exists($target_dir.$file)) @copy($source_dir.$file,$target_dir.$file); + } + } + } + } + + /** * @brief 파일의 내용을 읽어서 return **/