|
@@ -84,8 +84,8 @@ function pathJoin($base, $path) {
|
|
|
return $newPath;
|
|
|
}
|
|
|
|
|
|
-//拷贝文件到,自动创建目录,自动覆盖
|
|
|
-function fileCopy(string $filePath, string $targetPath){
|
|
|
+//拷贝文件,自动创建目录,自动覆盖
|
|
|
+function fileCopy(string $sourcePath, string $targetPath){
|
|
|
$targetDir = dirname($targetPath);
|
|
|
if(!is_dir($targetDir)){
|
|
|
createDirectory($targetDir);
|
|
@@ -94,10 +94,55 @@ function fileCopy(string $filePath, string $targetPath){
|
|
|
if( file_exists($targetPath) ){
|
|
|
unlink($targetPath);
|
|
|
}
|
|
|
- copy($filePath,$targetPath);
|
|
|
+ copy($sourcePath,$targetPath);
|
|
|
return file_exists($targetPath);
|
|
|
}
|
|
|
|
|
|
+//拷贝目录,自动创建目录,自动覆盖
|
|
|
+function dirCopy(string $sourceDir, string $targetDir){
|
|
|
+ if(! is_dir($targetDir)){
|
|
|
+ createDirectory($targetDir);
|
|
|
+ }
|
|
|
+ $dir = opendir($sourceDir);
|
|
|
+ while(false !== ( $file = readdir($dir)) ) {
|
|
|
+ if($file == '.' ){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if($file == '..' ){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $filePath = $sourceDir . '/' . $file;
|
|
|
+ $targetPath = $targetDir . '/' . $file;
|
|
|
+ if ( is_dir($filePath) ) {
|
|
|
+ if(! dirCopy($filePath,$targetPath) ){
|
|
|
+ logError('failed to copy dir',$filePath,'->',$targetPath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ copy($filePath,$targetPath);
|
|
|
+ if(! file_exists($targetPath) ){
|
|
|
+ logError('failed to copy file',$filePath,'->',$targetPath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ closedir($dir);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+//拷贝文件或目录
|
|
|
+function filedirCopy(string $sourcePath, string $targetPath){
|
|
|
+ if(! file_exists($sourcePath)){
|
|
|
+ logError('failed to copy file',$sourcePath,'->',$targetPath);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if( is_dir($sourcePath)){
|
|
|
+ return dirCopy($sourcePath,$targetPath);
|
|
|
+ }else{
|
|
|
+ return fileCopy($sourcePath,$targetPath);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//枚举子目录
|
|
|
function scanSubDir($dir,$exclude_names = array()){
|
|
|
$filelist = scandir($dir);
|