SysTem128
unread,Dec 7, 2007, 4:34:07 AM12/7/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cnPhpDevelop
<?php
class Direr
{
public $folder; #目录集合
public $filePath ; #文件集合
/**
* 装载目录和文件信息
*
* @param unknown_type $folder
* @param unknown_type $sufFix
* @return unknown
*/
public function setupFolder($folder = null,$sufFix = 'html')
{
$floderDirList = array();
settype($folder,'string');
if (is_dir($folder))
{
$folderList = glob($folder.'*');
$tplfileList = glob($folder.'*.'.$sufFix);
foreach ($tplfileList as $key => $value )
{
$filePath = $floder.$value;
if (is_file($value))
{
$filePathList[] = $filePath;
}
}
$this->insFilePath($filePathList);
$filePathList = null;
foreach ($folderList as $key => $value )
{
$floderDir = $floder.$value.'/';
if (is_dir($floderDir))
{
$floderDirList[] = $floderDir;
$this->setupFolder($floderDir,$sufFix);
}
}
$this->insFolder($floderDirList);
$floderDirList = null;
}
$this->insFolder($floderDirList);
return $floderDirList;
}
/**
* 推入目录信息
*
* @param unknown_type $folder
* @return unknown
*/
public function insFolder($folder = null)
{
$returnInfo = false;
if (is_array($folder) && !empty($folder))
{
$folderOld = $this->folder;
settype($folder,'array');
settype($folderOld,'array');
$this->folder = array_merge_recursive($folder,$folderOld);
$returnInfo = true;
}
return $returnInfo;
}
/**
* 获取目录信息
*
* @return unknown
*/
public function getFolder()
{
return $this->folder ;
}
/**
* 推入文件信息
*
* @param unknown_type $filePath
* @return unknown
*/
public function insFilePath($filePath = null)
{
$returnInfo = false;
if (is_array($filePath) && !empty($filePath))
{
$filePathOld = $this->filePath;
settype($filePathOld,'array');
$this->filePath = array_merge_recursive($filePath,$filePathOld);
$returnInfo = true;
}
return $returnInfo;
}
/**
* 获取文件信息
*
* @return unknown
*/
public function getFilePath()
{
return $this->filePath ;
}
public function creatFolder($folderList = null)
{
try {
foreach ($folderList as $folder)
{
if (!is_dir($folder))
{
mkdir($folder, 0700);
}
}
return true;
}
catch (Exception $e)
{
return false;
}
}
/**
* 复制文件
*
* @param unknown_type $sourceFilePathList
* @param unknown_type $targetFilePathList
* @return unknown
*/
public function copyFile($sourceFilePathList = null,$targetFilePathList = null)
{
try {
foreach ($targetFilePathList as $key => $value)
{
if (isset($sourceFilePathList[$key]))
{
$sourceFilePath = $sourceFilePathList[$key];
if (!is_file($value) && is_file($sourceFilePath))
{
copy($sourceFilePath,$value);
}
}
}
return true;
}
catch (Exception $e)
{
return false;
}
}
/**
* 替取目标文件夹名称列表
*
* @param unknown_type $item
* @param unknown_type $key
* @param unknown_type $replaceMent
*/
public function changeFolder(&$item,$key,$replaceMent)
{
$item = str_ireplace($replaceMent['source'],$replaceMent['target'],$item);
}
/**
* 复制目录所有目录与文件
*
* @param unknown_type $sourceFolder
* @param unknown_type $targetFolder
* @param unknown_type $sufFix
* @return unknown
*/
public function copyFolder($sourceFolder = null,$targetFolder = null,$sufFix = null)
{
$returnInfo = false;
do{
if(!is_dir($sourceFolder) || !is_dir($targetFolder))
{
break;
}
$this->setupFolder($sourceFolder,$sufFix);
$sourceFolderList = $this->getFolder();
$sourceFilepathList = $this->getFilePath();
$replaceMent['source'] = $sourceFolder;
$replaceMent['target'] = $targetFolder;
if (empty($sourceFolderList))
{
break;
}
$targetFolder = $sourceFolderList;
array_walk($targetFolder,array($this,'changeFolder'),$replaceMent);
if (!$this->creatFolder($targetFolder))
{
break;
}
if (empty($sourceFilepathList))
{
break;
}
$targetFilePath = $sourceFilepathList;
array_walk($targetFilePath,array($this,'changeFolder'),$replaceMent);
if (!$this->copyFile($sourceFilepathList,$targetFilePath))
{
break;
}
$returnInfo = true;
} while (0);
return $returnInfo;
}
// public function taxisFolder($a,$b)
// {
// $a = strlen($a);
// $b = strlen($b);
// if ($a == $b) {
// return 0;
// }
// return ($a > $b) ? -1 : 1;
//
// }
}
$direr = new Direr();
$sourceFolder = 'd:/Web_Root/Modules/Module/'; # 源文件夹
$targetFolder = 'd:/Web_Root/MMOODDUULLEESS/Module/'; #目标文件夹
////$direr->setupFolder($sourceFolder);
echo $direr->copyFolder($sourceFolder,$targetFolder,'php'); #操作 最后一参数为所需要拷贝的文件后缀
?>
--------------
SysTem128
2007-12-07