LinkPath

Title LinkPath
File Name LinkPath.txt
Description Put link to file to the clipboard
Author Vochomurka
Parameters "%P", "%T", "%M"
Plugins Called miscplugin, clip
Icon
Version 2.0
Updated on 26.01.2006
args P, T, M
local Result, i, BegP, BegT
local Bef = "<a href="
local Aft = "></a>"

if(P == T) do
	Result = Bef ++ M ++ Aft
	clip.set(Result)
	quit
endif

;Sub_ParsePath - name of script ParsePath
local SourceDepth = runfile.Subs\Sub_ParsePath(P, "")
local TargetDepth = runfile.Subs\Sub_ParsePath(T, "")

if(index(P, T) != 0) do
	Result = Bef ++ repeat("../", SourceDepth - TargetDepth) ++ M ++ Aft
	clip.set(Result)
	quit
endif

if(index(T, P) != 0) do
	Result = Bef ++ select(T, length(P) - length(T)) ++ M ++ Aft
	clip.set(Result)
	quit
endif

local Lim = min(SourceDepth, TargetDepth)
local Counter = 0

for(i = 1; i <= Lim; i = i + 1)
	Result = BegP
	BegP = runfile.Subs\Sub_ParsePath(P, i - SourceDepth)
	BegT = runfile.Subs\Sub_ParsePath(T, i - TargetDepth)
	if(BegP == "" || BegT == "")
		break

	if(BegP == BegT) do
		Counter = Counter + 1
	else
		break
	endif
endfor

if(Counter == 0) do
	local mpDlgCaption = "LinkPath Script"
	local mpIcon = "WARNING"
	local mpDlgText = "Source path is " ++ P ++ "\nTarget file is " ++ T ++ M
	mpDlgText = mpDlgText ++ "\nThey seem to be on different logical disks!"
	miscplugin.messagebox(1, "&OK")
	quit
endif

Result = repeat("../", SourceDepth - Counter)
Result = Result ++ runfile.Subs\Sub_ParsePath(T, TargetDepth - Counter) ++ "/"
Result = Bef ++ replacechars(Result, "\", "/") ++ M ++ Aft
clip.set(Result)

Comments:

Script can be useful for web-designers who often paste to their web pages the links to files located in different directories relative to the current one. It is supposed that the current directory in the source panel contains the web page file under editing. Further, in the opposite (target) panel you should place the cursor on the "target file", that is, file you need the link to. After pointing the target file you have to switch back to the source panel.

For example, the web page has the full name:

c:\One\Two\Three\Source.html

Links to target file Target.html depend on its path relative to the source path as follows:
Full path of target file Result
c:\One\Target.html <a href=../../Target.html></a>
c:\One\Two\Three\Target.html <a href=Target.html></a>
c:\Four\Five\Six\Target.html <a href=../../../Four/Five/Six/Target.html></a>
d:\Seven\Eight\Target.html Error!

Error in the last case is caused by different logical disks of source and target panels.

After the script execution you can easily paste the clipboard contents into your editor.

Since the path link is relative rather than absolute, the link will be valid irrespective of where both files (web page file and target file) are located: standalone computer, local or global network. Only one thing that must be kept is the directory structure.

Important! First line of script contains the args keyword introduced in PowerPro version 4.4! At execution under older versions the error message will be displayed. If (by some reason) you did not install the latest version of PowerPro, you should replace the first script line with the following three lines:

local P = arg(1)
local T = arg(2)
local M = arg(3)

Main Page Total Commander PowerPro