Created
February 9, 2015 03:53
-
-
Save takamin/8f9efef26dfb7bf73f9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(count($argv) != 2) { | |
exit; | |
} | |
$executable_suffixies = array("cmd", "bat", "dll", "exe"); | |
$filename = $argv[1]; | |
$no_suffix = !has_suffix($filename, $executable_suffixies); | |
$pathes = preg_split('/;/', getenv('PATH')); | |
foreach( $pathes as $path ) { | |
echo_file_exists("$path\\$filename"); | |
if($no_suffix) { | |
foreach($executable_suffixies as $suffix) { | |
echo_file_exists("$path\\$filename.$suffix"); | |
} | |
} | |
} | |
function has_suffix($filename, $suffixies) { | |
foreach($suffixies as $suffix) { | |
if(preg_match('/\.' . $suffix . '$/', $filename)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function echo_file_exists($filename) { | |
if(file_exists("$filename")) { | |
echo "$filename\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment