<?phpexec('chcp936');classfileHelper{private$handle;publicfunction__construct($dir){$this->handle=opendir($dir)...
<?php exec('chcp 936'); class fileHelper{ private $handle; public function __construct($dir){ $this->handle=opendir($dir); } public function getFileList(){ while (($item=readdir($this->handle))!==false) { if(strpos($item,'.jpg') !== false){ $FileList[]=$item; } } closedir($this->handle); return $FileList; } public function getDescFile($file){ $number=substr($file,0,-4); if(is_numeric($number)){ $descDir=floor($number/10000); }else{ $descDir='0'; } return $descDir; } function createDir($dir){ if(!is_dir($dir)){ mkdir($dir, 0777); } } } $param = getopt('',array('dir:')); if(count($param)==0){ $dir='./'; }else{ $dir=$param['dir']; } $fileHelper=new fileHelper('./'); $filelist=$fileHelper->getFileList(); $count=count($filelist); foreach($filelist as $key=>$value){ $dir=$fileHelper->getDescFile($value); $fileHelper->createDir("z:/TMlogo/".$dir); if(file_exists('Z:/TMlogo/'.$dir."/".$value)){ echo "Porcess:{$count} / {$key} ,$value is Exists\r\n"; unlink($value); }else{ echo "Porcess:{$count} / {$key} , Move:{$value} To: {$dir}\r\n"; rename($value,'Z:/TMlogo/'.$dir.'/'.$value); //unlink($value); } }
本代码实现将海量商标图片,如 12100101.jpg,移动到1210文件夹,不存在则新建。
全文详见:http://xpxw.com/?id=78