Skip to content

Instantly share code, notes, and snippets.

@cdeocampo
Created October 22, 2012 06:48
Show Gist options
  • Select an option

  • Save cdeocampo/3930015 to your computer and use it in GitHub Desktop.

Select an option

Save cdeocampo/3930015 to your computer and use it in GitHub Desktop.

Revisions

  1. cdeocampo created this gist Oct 22, 2012.
    19 changes: 19 additions & 0 deletions get_files.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php
    function getFiles($path, $extensions=null, &$files=null)
    {
    if(!is_dir($path)) return null;
    $files = ($files==null)?array():$files;
    $extensions = is_array($extensions) ? implode('|', $extensions) : $extensions;

    if ($handle = opendir($path)) {
    while (false !== ($entry = readdir($handle))) {
    if(preg_match("/^.*\.(". $extensions .")$/i", $entry)) {
    $files[] = $entry;
    } else if(is_dir($path.'/'.$entry) && !($entry == '.' || $entry == '..')) {
    $this->getFiles($path.'/'.$entry, $extensions, $files);
    }
    }
    closedir($handle);
    }
    return $files;
    }