私はこのコードを再帰的にファイルやディレクトリを削除する必要があります。それはうまく動作しますが、少し問題があります。 $ path =/var/www/foo /ならば、fooの中のすべてを削除しますが、fooは削除しません。私もfooディレクトリを削除したい。何か案が?再帰的削除
public function delete($path) {
if(!file_exists($path)) {
throw new RecursiveDirectoryException('Directory doesn\'t exist.');
}
$directoryIterator = new DirectoryIterator($path);
foreach($directoryIterator as $fileInfo) {
$filePath = $fileInfo->getPathname();
if(!$fileInfo->isDot()) {
if($fileInfo->isFile()) {
unlink($filePath);
}
else if($fileInfo->isDir()) {
if($this->emptyDirectory($filePath)) {
rmdir($filePath);
}
else {
$this->delete($filePath);
rmdir($filePath);
}
}
}
}
}
@stereofrog:ほぼすべて? – Bobby