有没有办法检查我的子目录中是否存在index.php?
例如:
home/
|__folder/
| |__index.php
| |__style.css
|
|__folder2/
| |__style.css
|
|__folder3/
|__text.txt
我想检查文件夹,folder2,folder3中是否有index.php。 最后,如果它不存在,我应该创建index.php。
答案 0 :(得分:0)
写一个快速的类来执行此操作,从命令提示符/终端运行。
class FolderChecker {
public function __construct() {
$this->scan_folder(getcwd());
}
public function scan_folder($folder) {
$scandir = scandir($folder);
if(file_exists($folder . "/index.php")) {
echo "index.php file exists in $folder\n";
} else {
echo "index.php file DOES NOT exists in $folder\n";
}
foreach($scandir as $scan) {
if($scan == "." || $scan == ".." || is_file($folder . '/' . $scan))
continue;
if(is_dir($folder . '/' . $scan))
$this->scan_folder($folder . '/' . $scan);
}
}
}
new FolderChecker;