迭代循环文件夹的处理方法

来源:互联网 发布:小米手机数据恢复软件 编辑:程序博客网 时间:2024/06/08 21:51

需求:


迭代循环一个目录下面的所有文件夹,找到所有的.svn的文件夹,然后进行处理,比如“删除”,


代码如下:


#!/usr/local/bin/phperror_reporting (0);if (count($argv) <= 1 || !is_dir($argv[1])) {die ("No file or directory to search!/n/n");}$rootDir = $argv[1];$trees = recursive_delete($rootDir);// print_r($trees);function recursive_delete($dir) {if (substr($dir, -1, 1) != DIRECTORY_SEPARATOR) {$dir = $dir . DIRECTORY_SEPARATOR;}if (is_dir($dir)) {if ($dh = opendir($dir)) {while (($file = readdir($dh)) !== false) {// echo $dir . $file . "\n";if ($file == ".svn") {if (is_dir($dir . $file)) {echo "Enter Directory: $dir$file\n";echo "Removing Directory: $dir$file\n";// rmdir($dir . $file);}} else if ($file != "." && $file != "..") {recursive_delete($dir . $file);}}}}}

仅供参考!

原创粉丝点击