Created
January 15, 2014 22:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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