function find_filepath($filename, $directory, $root, &$found)
{
    if (is_dir($directory)) {
        $Directory = @dir($directory);
        if ($Directory) {
            while (($file = $Directory->read()) !== false) {
                if (substr($file, 0, 1) == "." || substr($file, 0, 1) == "_") {
                    continue;
                }
                // Ignore .dot files and _directories
                if (is_dir($directory . DIRECTORY_SEPARATOR . $file) && $directory == $root) {
                    // Scan one deep more than root
                    find_filepath($filename, $directory . DIRECTORY_SEPARATOR . $file, $root, $found);
                } elseif ($file == $filename) {
                    $found[] = substr($directory, strlen($root)) . DIRECTORY_SEPARATOR . $file;
                }
                // Add the file to the found list
            }
            return true;
        }
    }
    return false;
}
Esempio n. 2
0
/**
 * Find a target file starting at a given directory
 * 
 * @since 1.1
 * @param string $filename The target file to find
 * @param string $directory The starting directory
 * @param string $root The original starting directory
 * @param array $found Result array that matching files are added to
 **/
function find_filepath ($filename, $directory, $root, &$found) {
	if (is_dir($directory)) {
		$Directory = @dir($directory);
		if ($Directory) {
			while (( $file = $Directory->read() ) !== false) {
				if (substr($file,0,1) == "." || substr($file,0,1) == "_") continue;				// Ignore .dot files and _directories
				if (is_dir($directory.'/'.$file) && $directory == $root)		// Scan one deep more than root
					find_filepath($filename,$directory.'/'.$file,$root, $found);	// but avoid recursive scans
				elseif ($file == $filename)
					$found[] = substr($directory,strlen($root)).'/'.$file;		// Add the file to the found list
			}
			return true;
		}
	}
	return false;
}