4 * Support functions for the importImages script
8 * @author Rob Church <robchur@gmail.com>
12 * Search a directory for files with one of a set of extensions
14 * @param $dir Path to directory to search
15 * @param $exts Array of extensions to search for
16 * @return mixed Array of filenames on success, or false on failure
18 function findFiles( $dir, $exts ) {
19 if( is_dir( $dir ) ) {
20 if( $dhl = opendir( $dir ) ) {
21 while( ( $file = readdir( $dhl ) ) !== false ) {
22 if( is_file( $dir . '/' . $file ) ) {
23 list( /* $name */, $ext ) = splitFilename( $dir . '/' . $file );
24 if( array_search( strtolower( $ext ), $exts ) !== false )
25 $files[] = $dir . '/' . $file;
38 * Split a filename into filename and extension
40 * @param $filename Filename
43 function splitFilename( $filename ) {
44 $parts = explode( '.', $filename );
45 $ext = $parts[ count( $parts ) - 1 ];
46 unset( $parts[ count( $parts ) - 1 ] );
47 $fname = implode( '.', $parts );
48 return array( $fname, $ext );