Skip to content

Instantly share code, notes, and snippets.

@babsgosgens
Forked from AmyStephen/list.php
Created August 3, 2012 07:04
Show Gist options
  • Save babsgosgens/3245270 to your computer and use it in GitHub Desktop.
Save babsgosgens/3245270 to your computer and use it in GitHub Desktop.
To create a .gitignore with a list of all files in Repository
<?php
/**
* @package Molajo
* @copyright 2012 Amy Stephen. All rights reserved.
* @license GNU GPL v 2, or later and MIT, see License folder
*
* Place in the root of your website - execute it - and copy the results into your .gitignore
*/
$current_path = __DIR__;
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($current_path),
RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
if($object->isDir()) {
$dirRead = dir($name);
$path = $dirRead->path;
while (false !== ($entry = $dirRead->read())) {
if (is_dir($path . '/' . $entry)) {
} else {
$item = $path . '/' . $entry . '<br />';
echo substr($item, strlen($current_path) + 1, 99999);
}
}
$dirRead->close();
}
}
/** Current */
$dirRead = dir(__DIR__);
$path = $dirRead->path;
while (false !== ($entry = $dirRead->read())) {
if (is_dir($path . '/' . $entry)) {
} else {
$item = $path . '/' . $entry . '<br />';
echo substr($item, strlen($current_path) + 1, 99999);
}
}
$dirRead->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment