Skip to content

Instantly share code, notes, and snippets.

@realityking
Created November 8, 2011 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realityking/1346705 to your computer and use it in GitHub Desktop.
Save realityking/1346705 to your computer and use it in GitHub Desktop.
index.html creator
#!/usr/bin/php
<?php
if (php_sapi_name() != "cli") {
echo "Error: phptidy has to be run on command line with CLI SAPI\n";
exit(1);
}
function getDirectory($path = '.', $level = 0) {
// Directories to ignore when listing output.
$ignore = array('.', '..');
$dh = opendir($path);
while (($file = readdir($dh)) !== false)
{
// Check for ignored files/folders
if (!in_array( $file, $ignore)) {
if (is_dir($path.'/'.$file)) {
// Add an index.html if neither an index.html nor an index.php exist
if (!(file_exists($path.'/'.$file.'/index.html') || file_exists($path.'/'.$file.'/index.php'))) {
file_put_contents("$path/$file/index.html", '<!DOCTYPE html><title></title>'."\n");
}
// And the recursion
getDirectory($path.'/'.$file, ($level+1));
}
}
}
closedir($dh);
}
$work = $_SERVER['argv'][1];
echo "Working on directory ".$work."\n";
getDirectory($_SERVER['argv'][1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment