You appear to be a bot. Output may be restricted
Description
Drill down to locate the lowest fileIn Windows, when you're using symlinks and PHP's chdir() the resulting directory reported by getcwd() reflects the real directory. This might not be the one you first thought of. It makes finding files a little tricky, hence the need for this function.
Usage
$string|null = oik_batch_cd_drill_down( $path, $locate_file );
Parameters
- $path
- ( string ) required – the ending directory
- $locate_file
- ( string ) optional default: wp-config.php – the file we're looking for
Returns
string|null the lowest directory or nullSource
File name: oik-batch/libs/oik-cli.phpLines:
1 to 20 of 20
function oik_batch_cd_drill_down( $path, $locate_file="wp-config.php" ) { $abspath = null; $path = str_replace( "\\", "/", $path ); $paths = explode( "/", $path ); foreach ( $paths as $cd ) { $success = chdir( $cd ); if ( $success ) { $now = getcwd(); //echo "$cd got me here $now" . PHP_EOL; if ( file_exists( $locate_file ) ) { $abspath = $now; $abspath .= '/'; echo "Found $locate_file in: $abspath" . PHP_EOL; } } else { echo "Error performing chdir to $cd" . PHP_EOL; } } return( $abspath ); }View on GitHub