GoClipped

Title GoClipped
File Name GoClipped.txt
Description Move the cursor to the file (or open the directory) whose name is in the clipboard
Author Vochomurka
Parameters Path, FileDir, NewTab, Target
Plugins Called win, clip
Icon
Version 1.1
Updated on 12.07.2010
args Path, FileDir, NewTab, Target
local hwnd = win.handle("c=TTOTAL_CMD")
local Str = clip.get

if(not FileDir)
	Str = Path ++ Str

if(not validpath(Str)) do
	if(validpath(Str ++ ".*")) do
		Str ++= ".*"
	else
		messagebox ("ok", "Invalid path: " ++ Str, "GoClipped script")
		quit
	endif
endif

local Quote = esc(?+\"+, ?+\+)
local Exepath = win.exepath(hwnd)
local Pars = "/O /S /"

if(NewTab)
	Pars = "/T " ++ Pars

Pars = Pars ++ ifelse(Target, "R=", "L=")

do(Exepath, Pars ++ Quote ++ Str ++ Quote)

Comments:

First parameter is "%P" (source panel) or "%T" (target panel). Although any real path can be provided, but if the path contains spaces, it must be included in quotes. If the file name has no extension, cursor goes to the first file with the given name.

Second parameter is 0 or "" if the clipboard contains the file name (without path). In this case the cursor is moved to the file in the current (if first parameter is "%P") or opposite ("%T") directory. That is, for "%T" the source path gets the same as the target path. If the second parameter is 1 (or anything other than 0 or ""), then the directory from the clipboard is opened in the source (not target) panel. Further, if second parameter is 1, then the first one is not used, but must be present (for example, "").

If third parameter is 0 or "", the current tab is used. If anything else (1 is the best), then the new tab is opened.

If fourth parameter is 0, "", or absent, the source panel is changed. If anything else, then the target panel is changed according to the clipboard contents.

Suppose the source panel path is c:\one\two, the target one is d:\three\four.

Clipboard contents Script parameters Result
abc.txt "%T", 0, 0, 0 Cursor moves to d:\three\four\abc.txt*
abc.txt "%P", 0, 0, 0 Cursor moves to c:\one\two\abc.txt*
c:\one\two "%P", 0, 0, 0 Error message: no file name is given
c:\one\two\abc.txt **, 1, 0, 0 Cursor moves to c:\one\two\abc.txt*
c:\one\two **, 1, 0, 0 Cursor moves to c:\one\two\
abc.txt "%P", 0, 1, 0 Cursor moves to c:\one\two\abc.txt* in new tab
c:\one\two\abc.txt **, 1, 1, 0 Cursor moves to c:\one\two\abc.txt* in new tab
c:\one\two **, 1, 0, 1 Path c:\one\two\ is opened in the target panel. Cursor doesn't move.
abc.txt c:\one\two\, 0, 0, 0 Cursor moves to c:\one\two\abc.txt*
* If file exists, error message otherwise.
** Can be arbitrary.

In all cases the cursor stays in the source panel.

Best combinations of parameters are ("%P", 0, 0, 0) for file name in the clipboard (current directory), and ("", 1, 0, 0) for path with or without file name.


Main Page Total Commander PowerPro