Last active
March 9, 2019 15:18
-
-
Save xandeadx/6ca1b50235b93b4f9bbdfbbeaa7ccb33 to your computer and use it in GitHub Desktop.
Total Commander open siblings directory
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 | |
$directory = $argv[1] ?? ''; | |
$direction = $argv[2] ?? ''; | |
if (!$directory || !in_array($direction, ['prev', 'next'])) { | |
exit('Invalid parameters'); | |
} | |
$directory = rtrim($directory, DIRECTORY_SEPARATOR); | |
$parent_directory = dirname($directory); | |
$parent_directory_items = scandir($parent_directory); | |
$directories = []; | |
foreach ($parent_directory_items as $item) { | |
if ($item != '.' && $item != '..' && is_dir($parent_directory . DIRECTORY_SEPARATOR . $item)) { | |
$directories[] = $parent_directory . DIRECTORY_SEPARATOR . $item; | |
} | |
} | |
$directory_index = array_search($directory, $directories); | |
$sibling_directory_index = ($direction == 'next') ? $directory_index + 1 : $directory_index - 1; | |
$sibling_directory = isset($directories[$sibling_directory_index]) ? $directories[$sibling_directory_index] : ''; | |
if ($sibling_directory) { | |
exec('"D:\Programs\System\Total Commander\TOTALCMD64.EXE" "' . $sibling_directory . '" /O /S'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment