Swap drive letter and folder and Go to folder

I have a "hard" time figuring out how to create a command to take a selected file or files, figure out their folder and swap the root drive out and go to that "mirror" place.

I have a mapped network drive Z:\Projects, it has an equivalent in P:\root\Projects. I would like to have an action that reads the folder that is currently open, replace z:\ with p:\root\ and open that folder. As a bonus the restore selection would be great, but I could do without :slight_smile:

I tried a Jscript and got the filename swapping working if I print it out, but I'm not sure how to set the current tab to that new location.

Here's the Jscript

function OnClick(clickData)
{

	DOpus.ClearOutput();

	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection

	if (clickData.func.sourcetab.selected.count == 0)
	{
		DOpus.Output("  (none)");
	}
	else
	{
		var file = clickData.func.sourcetab.selected(0);
		var newpath = String(file).toLowerCase().replace("z:", "P:\\root");
		DOpus.Output(newpath);
		cmd.SetSource(newpath);
	}
}

SetSource does nothing. Also if there's a better way I'd love to know!

Thanks!
-Johan

Instead of cmd.SetSource(newpath);, use this:

cmd.RunCommand('Go PATH="' + newpath + '"');

(Edit: Fixed typo.)

Nice, that works! Thanks!
Small typo, with a single quote ( ' ) for Go.

Again thanks!
-Johan

1 Like

Strings in JScript can use either single or double-quotes; it lets you use one type to surround the string and embed the other easily in the string. So in this case Leo used single quotes so that double-quotes could be easily embedded in the command line, which means paths with spaces in them will work.

I originally left out one of the single quotes, which probably confused things.