1.匹配指定的关键字查找文件 2.匹配到文件后再执行相应的系统命令或生成批处理文件 3.反馈执行结果 4.示例:$phpfind.phpd:/photo.jpg,.gif,.pnggmconvert-resize200X200$filename$filename 5.示例解释:查找d:/photo下的所有文件夹及子文件夹jpg,gif,png格
1.匹配指定的关键字查找文件
2.匹配到文件后再执行相应的系统命令或生成批处理文件
3.反馈执行结果
4.示例:$php find.php d:/photo .jpg,.gif,.png "gm convert -resize 200X200 $filename $filename"
5.示例解释:查找d:/photo下的所有文件夹及子文件夹jpg,gif,png格式,调用GraphicsMagick工具转换尺寸为200*200,并覆盖原来的文件
read())) {
if($currentPath[strlen($currentPath) - 1] == '/') {
$filename = $currentPath . $name;
} else {
$filename = $currentPath . '/' . $name;
}
if($name == '..' || $name == '.') {
continue;
}
if(is_dir($filename)) {
$directory[] = $filename;
} else {
str_replace(explode(',', $match), '', $name, $count);
if($match != '*' && $count == 0) {
continue;
}
$template = array('$name', '$filename', '$path', '$index');
$variable = array($name, $filename, $currentPath, $index);
$cmd = str_replace($template, $variable, $command);
if(CREATE_BAT_FILE) {
$result .= $cmd . PHP_EOL;
} else {
echo shell_exec($cmd);
}
$index++;
}
}
next($directory);
}
// create bat file
if(CREATE_BAT_FILE) {
$batFile = fopen('temp.bat', 'w');
fwrite($batFile, $result);
fclose($batFile);
echo 'output file to: ' . str_replace('\\', '/', __DIR__) . '/temp.bat' . PHP_EOL;
}
// echo result:
echo $index . ' file find.' . PHP_EOL;
本文原创发布php中文网,转载请注明出处,感谢您的尊重!