Cycle through a list of paths

Path Cycling:

Path cycling lets you create a single toolbar button or hotkey which you can push to cycle through a list of paths.

Two Paths:

Opus has built-in support for toggling between two paths. The Go command's SWITCHPATH argument can be used to do that:

Go PATH="C:\Program Files" SWITCHPATH="C:\Windows"

With that command:

  • If you are in C:\Program Files then you'll go to C:\Windows.
  • If you are in C:\Windows then you'll go to C:\Program Files.
  • If you are in any other path then you'll also go to C:\Program Files.

Three or more paths (Opus 9.1.1.6 or above):

With Opus 9.1.1.6 and above you can give multiple paths to the Go SWITCPATH command. For example:

Go C:\ SWITCHPATH F:\ G:\ H:\

With that command:

  • If you are in C:\ then you'll go to F:.
  • If you are in F:\ then you'll go to G:.
  • If you are in G:\ then you'll go to H:.
  • If you are in H:\ then you'll go to C:.
  • If you are in any other path then you'll also go to C:.[/li][/ul]
Go "C:\Program Files" SWITCHPATH C:\Windows C:\Windows\System32

With that command:

  • If you are in C:\Program Files then you'll go to C:\Windows.
  • If you are in C:\Windows then you'll go to C:\Windows\System32.
  • If you are in C:\Windows\System32 then you'll go to C:\Program Files.
  • If you are in any other path then you'll also go to C:\Program Files (since it's first in the list).

Three or more paths (before Opus 9.1.1.6):

We used to have a kludge here for older versions of Opus which (ab)used a Rename script to cycle three or more paths. That isn't a good way to do things now, and really just complicates matters, so it has been removed. You might find some other threads in the forum that reference the old Rename-script method, so I've left mention of it here to avoid confusion with the newer methods.

You can look up this posts's edit history if you really want to see the old method, but it's not recommended. There are better ways to do it now, either using the commands above, or using proper scripting if you want to do something extra, like in tbone's example below.

This is an alternative way to cycle paths using a script to control things.

This allows us to have extra custom logic. In this case, I want the same path to appear in the cycle more than once:

H:
F:
H:
I:
H:\

Cycle Paths (C F G H + Folders).dcf variation for DO v11 & above:

Remove the OPENINDUAL keyword for looping the path in the current file display and to fully match the "Cycle Paths (C F G H + Folders).dcf" behaviour.

var loop = new PathLoop().AddPath("H:\\").AddPath("F:\\").AddPath("H:\\").AddPath("I:\\").AddPath("H:\\");
///////////////////////////////////////////////////////////////////////////////
function OnClick(data){
	var f = data.func, c = f.command, tab = f.sourcetab, path2 = ""+tab.path;
	var root = (tab.path.Root() && tab.path) || tab.path, subpath = (""+path2).replace(root,"");
	c.RunCommand('Go OPENINDUAL PATH="'+loop.NextPath(root)+subpath+'"'); //keep subfolders, loop roots only, OPENINDUAL
}
///////////////////////////////////////////////////////////////////////////////
function PathLoop(){
	this.list = [];
	this.AddPath = function (path){
		var o = { path: path.toLowerCase(), next: this.list.length ? this.list[0]: this};
		this.list[this.list.length] = o;
		if (this.list.length>1) this.list[this.list.length-2].next = this.list[this.list.length-1];
		return this;
	}
	this.NextPath = function(curPath){
		var cPL = (""+curPath).toLowerCase();
		for(var i=0;i<this.list.length;i++) if (this.list[i].path==cPL) return this.list[i].next.path;
		return this.list[0].path;
	}
}