Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Recursively searches the current directory and deletes any file that has only an opening PHP tag and empty lines
* Thanks to Jan for providing the solution here:
$directory = new RecursiveDirectoryIterator('./');
$iterator = new RecursiveIteratorIterator($directory);
$regex = '~\A\Q<?php\E\s+\Q\E\Z~';
$deletedCount = 0;
foreach($iterator as $name => $file) {
$content = file_get_contents($file);
if (preg_match($regex, $content)) {
print "deleted " . $name . "\n";
print "Deleted $deletedCount empty files.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.