Directory Contents - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21) +---- Thread: Directory Contents (/showthread.php?tid=2607) |
Directory Contents - zone - 11-06-2009 Credits and Source: http://www.dreamincode.net/ Name: Directory Contents Description: This snippet takes a directory and returns or excludes certain files/directories from the output. Snippet: PHP Code: <?php Instructions: string $dir: directory you wish to search array $ear: an array of regular expressions with what you wish to include or exclude from the results boolean $invert: whether you wish to include or exclude TRUE = include, FALSE = exclude integer $type: a flag setting which will include files or directories inclusively or exclusively, FILE_FLAG for files, DIR_FLAG for directories, and FILE_FLAG | DIR_FLAG for both RETURNS array $far: an array with files/directories Examples: // prints all the folders in the directory print_r('.', getArtefacts(array('.*\.[a-z0-9]{3,4}'))); print_r(getArtefacts('.', array(), false, DIR_FLAG)); // prints all the files in the directory print_r('.', getArtefacts(array('.*\.[a-z0-9]{3,4}'), true)); print_r(getArtefacts('.', array(), false, FILE_FLAG)); // prints all .htm or .html files in the directory print_r('.', getArtefacts(array('.*\.html*'), true)); // prints all files that don't end in .htm or .html print_r('.', getArtefacts(array('.*\.html*'), false, FILE_FLAG)); Thankyou for reading |