SameDir

Title SameDir
File Name SameDir.txt
Description Open the same directory on another drive
Author Vochomurka
Parameters "path", "drive"
Plugins Called file, win, miscplugin
Icon depends on drive
Version 1.0
Updated on 12.07.2010
args Path, Where
local Source = Path[0, 2]
local Len = length(Path)
local Source, Target
local Str, Dir, i
static Disks = file.alldrives
static Quote = esc(?+\"+, ?+\+)
local Num = line(Disks, 0)
flag set 1

for(i = 1; i <= Num; i++)
	Str = line(Disks, i)
	if(Str == Source) do
		flag clear 1
		Dir = slice(Path, 3 - Len)
		break
	endif
endfor

if(pproflag(1)) do
	messagebox("ok error", "Current drive not found", "SameDir Script")
	quit
endif

local hwnd = win.handle("c=TTOTAL_CMD")
local Exepath = win.exepath(hwnd)

Str = ifelse(miscplugin.is_int(Where), line(Disks, i + Where), Where ++ ":\" ) ++ Dir

if(not validpath(Str)) do
	messagebox("ok error", "Invalid path: " ++ Str, "SameDir Script")
	quit
endif

do(Exepath, "/O /S /L=" ++ Quote ++ Str ++ Quote)

Comments:

If current path is c:\path, the script changes it to d:\path or f:\path, that is, the same path on another drive, but only if such path exists.

First parameter can be "%P", "%T", or any explicit path. Second parameter can be numeric or alphabetic. In the first case one of previous (negative number), or next (positive one) drives is used. Suppose the current path is d:\dir1\dir2, and the script paramaters are ("%P", 2), then path f:\dir1\dir2 is open. Alphabetic one letter parameter points to some specific drive. For exmple, if target (inactive) path is any_drive:\dir1\dir2 and script parameters are ("%T", "g"), then the g:\dir1\dir2 path is open.


Main Page Total Commander PowerPro