From 10c48da98aeecf08bac94388775f17f5e6691f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Fri, 24 Jan 2014 13:48:13 +0800 Subject: [PATCH] Fix recursive issue ( -r flag ) --- php/regRename.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/php/regRename.php b/php/regRename.php index cc0f33c..5712a78 100644 --- a/php/regRename.php +++ b/php/regRename.php @@ -49,16 +49,14 @@ function getFileList ( $dir ) { } function getDirList ( $dir ) { - $dirList = array(); - $iterator = new DirectoryIterator ( getDirName ( $dir ) ) ; + $dirList = array(); + $iterator = new DirectoryIterator ( getDirName ( $dir ) ) ; foreach ( $iterator as $fileinfo ) { - if ( $fileinfo->isDir() ) { + if ( $fileinfo->isDir() && !$fileinfo->isDot()) { $dirList[] = $fileinfo->getFilename(); } - } - //Chop dir "." and ".." - array_shift ( $dirList ) ; - array_shift ( $dirList ) ; + } + return $dirList; } @@ -206,7 +204,7 @@ foreach ( $searchDirs as $dir ) { } if( $matches[2][0] != $newName ) { if( $test ) { - echo "File \"{$matches[2][0]}\" will renamed to \"$newName\"\n"; + echo "File \"{$matches[2][0]}\" will be renamed to \"$newName\"\n"; } else { rename ( $file, "{$matches[1][0]}$newName" ); } @@ -225,4 +223,4 @@ if ( $test ) echo "*** Test enabled ***\n\n"; //------- End Operations -------*/ -?> \ No newline at end of file +?>