Rename folders nad files recursivly in PHP
hi i am woking on reading the folder structure recursivly and find the
files and save those files in DB my intension is to change all the folders
and file names to upper case it generates the error i wrote the code like
this
function generateData() {
$dir = APP . 'views' . DS . 'static' . DS. 'services';
$this->files = null;
$list= $this->_getData($dir);
$listOfFiles = $this->files;
}
function _getData($dir) {
$files = array();
$parId = 4;
$rootPath = '/static' . DS. 'services'.DS;
$tmpPath = $viewPath = '';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($dir.'/'.$file)) {
$dir2 = $dir.'/'.$file;
LogUtil::$logger->debug('Directory :'.$dir2);
$tmpPath =
str_replace('/opt/workspace/KMP/cake_install/app/views'.$rootPath,'',$dir2);
$fldrData = scandir($dir2);
$viewPath = (count($fldrData) == 2) ? 'download_files'
: 'sections';
foreach ($fldrData as $info){
if ($info != "." && $info != "..") {
$viewPath = (is_dir($dir2.'/'.$info)) ?
'sections' : 'download_files';
}
}
(count(explode('/', $tmpPath)) == 1) ?
$this->_saveData(++$this->kmpId,$dir2,$parId,1,$viewPath)
:
$this->_saveData(++$this->kmpId,$dir2,-1,1,$viewPath);
$chngPath =
str_replace('/opt/workspace/KMP/cake_install/app/views/static','',$dir2);
$basePath =
'/opt/workspace/KMP/cake_install/app/views/static';
rename($basePath.$chngPath,$basePath.strtoupper($chngPath));
$this->_getData($dir2);
}
else if($file != ''){
LogUtil::$logger->debug('--File :'.$dir.'/'.$file);
$this->_saveData(++$this->kmpId,$dir.'/'.$file,-1,0);
$this->files[] = $dir.'/'.$file;
}
}
}
closedir($handle);
}
}
savedata function is working fine when i am trying to excecute i get the
follwing error for all folders and files
rename(/opt/workspace/KMP/cake_install/app/views/static/services/automation_testing,/opt/workspace/KMP/cake_install/app/views/static/SERVICES/AUTOMATION_TESTING)
[function.rename]: No such file or directory
[APP/controllers/util_code_controller.php, line 809]
No comments:
Post a Comment