I've taken the dangerous liberty of adding some bells and whistles to leo's script. Apologies, leo, in advance for my inevitable mistakes and misunderstandings. In particular, I'm not confident that I've understood the significance of all the checks in the code.
I rewrote it in JScript because I don't know VBScript, and renamed it from Go_to_Relative.vbs to GoRelative.js to avoid confusion with leo's script.
Drive-hopping is added. That is, if the script climbs to the root of a drive rather than a directory, then it will hop to the next or previous drive in alphabetical order.
— This drivehopping ignores drives that are not ready, but otherwise does not distinguish between types of drives (one could easily add such code).
— A new switch argument ChooseDrive of type /S triggers a dialogue for the user to choose the target drive, rather than have it chosen automatically.
— Another new argument OmitDrives of type /K can avoid annoying things such as HP's naming of their backup drive as D: drive. For example,
OmitDrives=D:,M:,Z: (OmitDrives=D,M,Z and OmitDrives=D:\,M:\,Z:\ will also work).
More significantly, a new argument Depth, of type /O, allows automatic navigation through parallel directory structures. By itself or with an invalid value, it triggers a dialogue, otherwise it should have a positive whole number as its value.
— Depth=1 is the default if the Depth argument is not mentioned. This makes the script behave as before.
— Depth=2 climbs two steps instead of one up and then down the directory tree. For example, suppose that there are two directories:
...\Lessons\2016\Class09 AND ...\Lessons\2017\Class09
Suppose that one is working in the \Lessons\2017\Class09 directory, and wants to go to \Lessons\2016\Class09 to pick up something from last year's directory. The following two buttons swap between them:
GoRelative Depth=2 Sibling=Previous (or Sibling=-1)
GoRelative Depth=2 Sibling=Next (or Sibling=1)
— Depth=3 extends this climb one more step. Suppose that there are two directories:
The following two buttons swap between them:
GoRelative Sibling=Previous Depth=3
GoRelative Sibling=Next Depth=3
— And so on. Depth=4 would be for ...Lessons\2016\Class09\Quadratics\Tests.
For depths greater than 1, the tree-climbing may comes to a drive prematurely. In this situation, the climbing stops, and drive-hopping begins.
Once the depth is greater than 1, the parallel target directory may not exist. When this happens, the script goes as far back down the target tree as far as it can, then issues a warning message.
The Sibling argument is now of type /O. The chosen sibling may be 1, 2, 3, ... away, which may be useful when the depth is greater than 1.
— When the argument is absent (not recommended), it defaults to the Next sibling directory (or drive).
— The argument Sibling can take any non-zero integer, where positive integers move forward that many items through the siblings, and negative numbers move backwards through the siblings.
— The argument Sibling can also take, as it did before, the values Next (=1), Previous (=-1) or Prev, which move to the next or previous sibling.
— By itself or with an invalid value, the argument Sibling triggers a dialogue.
— The switch argument Wrap of type /S now uses modulo arithmetic in the obvious way.
In particular, the command GoRelative with no Sibling argument is the same as GoRelative Sibling=Next or GoRelative Sibling=1.
The default is now to include hidden files, but exclude system files. These defaults can be changed with two switches of type /S:
— SkipHidden (unchanged) and IncludeSystem (new).
In a DOpus thread a year or so ago, I posted a system using the keys F12, F11, F10 and F9, for opening directories in another tab, the other dual panel, or another single- or dual-panel lister. These methods now work consistently with the GoRelative commands.
I had already implemented, and posted above, a less elaborate version of 'depth' using leo's unaltered script combined with ordinary DOpus commands. But the F12-F9 methods did not work consistently with these earlier 'depth' buttons, perhaps because of timing issues, and this was my original motivation for fiddling with leo's script.
— A new switch UserDefinedGo, of type /S, now changes the final command from DOpus' normal Go command to the user-defined command A@Go used in the F12--F9 system. Obviously, ignore this switch entirely unless the F12--F9 system is already installed and running.
[To recapitulate this system, before running the script:
Press F12 to open the new folder in a new tab.
Press F11 to open it in the dual panel.
Press F12 and F11 to open it in a new tab of the dual panel.
Press F10 to open it in a single-panel lister.
Press F9 to open it in a dual-panel lister.
See the earlier thread for the code to attach to F12-F9 and the corresponding menubar icons, where the hotkeys are arbitrary, or could be omitted.]
SOME EXAMPLE CODES FOR BUTTONS (WITHOUT THE SWITCH UserDefinedGo):
GoRelative Sibling=Next Wrap Depth=1 — Totally standard
GoRelative Sibling=Previous Depth ChooseDrive SkipHidden — Dialogues for the depth and the drive.
GoRelative Sibling Wrap Depth=2 OmitDrives=M:,Z: — Dialogue for the sibling, and Drives M: and Z: are omitted if drive-hopping is necessary.
The file below is the adapted GoRelative.js script. I was not sure how to handle the copyright protocols, which may well need adjusting.
First, disable the old addon Go_to_Relative.vbs if it is installed, otherwise DOpus will have two conflicting commands GoRelative. The easiest way is to navigate to the addons directory and rename its extension to .vbsx — this is easily reversed in the event of blunders by me.
Download the new file GoRelative.js.txt below, open the scripts window by Preferences --> Toolbars --> Scripts, and drag the downloaded file to its right-hand panel.
GoRelative.js.txt (14.8 KB)