Skip to content

Instantly share code, notes, and snippets.

@NuclearMonster
Created January 15, 2014 22:17
Show Gist options
  • Save NuclearMonster/8445831 to your computer and use it in GitHub Desktop.
Save NuclearMonster/8445831 to your computer and use it in GitHub Desktop.
Populate a git repo with .gitignore files so that you'll get the structure you want. Execute with php populate.php on the command line. I got it from this stack overflow thread: http://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository and just edited it because I didn't want empty README files.
<?php
$path = realpath('.');
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
if ( is_dir($name) && ! is_empty_folder($name) ){
echo "$name\n" ;
exec("touch ".$name."/".".gitignore");
}
}
function is_empty_folder($folder) {
$files = opendir($folder);
while ($file = readdir($files)) {
if ($file != '.' && $file != '..')
return true; // not empty
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment