Do user commands support relative paths?

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

desslok
Bronze Member
Bronze Member
Posts: 167
Joined: 2008 Jan 16, 22:10

Post by desslok »

Do user command support relative paths?
User avatar
nikos
Site Admin
Site Admin
Posts: 15802
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

relative to what? You can't have plain relative paths since xplorer2 changes its current directory as you browse. What you could do is have commands including environmental variables like

Code: Select all

> %windir%\notepad
desslok
Bronze Member
Bronze Member
Posts: 167
Joined: 2008 Jan 16, 22:10

Post by desslok »

Relative to the location of xplorer2. So if I have a portable program inside the xplorer2 folder, can I do something like:

Code: Select all

./foobar/foobar.exe
User avatar
nikos
Site Admin
Site Admin
Posts: 15802
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

the only way i can think of is to define a new environmental variable that will hold the path to x2 and then build your user commands based on it. Perhaps i'll make x2 add a special environmental variable of its own that holds its path
desslok
Bronze Member
Bronze Member
Posts: 167
Joined: 2008 Jan 16, 22:10

Post by desslok »

OK, please consider it. Custom association or commands are important to me when it comes to portability.
User avatar
fgagnon
Site Admin
Site Admin
Posts: 3737
Joined: 2003 Sep 08, 19:56
Location: Springfield

Post by fgagnon »

Is there not a workaround with "Don't lock current folder" invoked?

In that case, I thought x2 does not change wkg directory as it browses, but keeps it at its installation folder (or whatever folder was active when you elect the option).
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry »

Since version 1.7.0.x "don't lock browsed folder" sets the current working directory to the folder that something is launched from by double clicking on it or using the x2 command line. So there is no guarantee that CWD will remain set to the x2 install folder.

Try this:

Code: Select all

@echo off
set x2drive=%~d0
set x2path=%~dp0
start xplorer2_UC.exe /P
put this batch file in the x2 folder and use it to start x2 then use the x2path variable in your user commands. For example:

>%x2path%\editor2_UC.exe "$F"

You have to be running Windows 2000 or above for this to work, WIndows 9x (or Me) does not support the %~ modifier.

If your x2 path has spaces then do:

>"%x2path%\editor2_UC.exe" "$F"

Edit: added /P parameter, added x2drive variable
Last edited by FrizzleFry on 2008 Apr 18, 14:53, edited 3 times in total.
User avatar
nikos
Site Admin
Site Admin
Posts: 15802
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

what on earth is ~dp0?
tonne
Member
Member
Posts: 25
Joined: 2006 May 26, 10:35

Post by tonne »

Explained here (the for command).
%~dpI Expands %I to a drive letter and path only.
Also works for parameters to batchfiles:
%~dp0 Expands %0 to a drive letter and path only.
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry »

I like SS64.com for command line info. This page explains the ~ modifiers.

%~dp0 returns the drive and path of the batch file.

By placing the batch file in the x2 folder and using it to execute x2, the x2path variable, which the batch file creates, is inherited by the x2 process and can be used in user commands.

The drawback is that these user commands (which use x2path) will not work if you do not use the batch file to execute x2.
Last edited by FrizzleFry on 2008 Apr 16, 17:07, edited 2 times in total.
User avatar
nikos
Site Admin
Site Admin
Posts: 15802
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Post by nikos »

you guys are way hard core  :lol:
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry »

It was your idea... this just provides a method of using it now :)
desslok
Bronze Member
Bronze Member
Posts: 167
Joined: 2008 Jan 16, 22:10

Post by desslok »

FrizzleFry,

Did you actually try that? It's not working on my Vista. I double checked everything including quotion marks.
User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1241
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry »

I did test it but I am running XP not Vista.

See if the x2 process is inheriting the x2path variable.

After you run the batch file, which runs x2, open a command prompt from x2 (F10, Enter). then type set and look for x2path or echo %x2path%.

If you cannot find the x2path then Vista is handling inheritance differently than XP and 2000 do and this will not work. If the x2path variable is set correctly then the user command is incorrect.

Another problem is that you need to exit all other x2 processes before you run the batch file otherwise the new instance will run in the previous processes' environment.
Last edited by FrizzleFry on 2008 Apr 16, 19:47, edited 1 time in total.
desslok
Bronze Member
Bronze Member
Posts: 167
Joined: 2008 Jan 16, 22:10

Post by desslok »

x2path is there:

Code: Select all

x2path=C:\Program Files\zabkat\explorer2\
My User command is:

Code: Select all

>"%x2path%\editor2_UC.exe"
It's not working. What's wrong?

Edit:

Code: Select all

>editor2_UC.exe
This works :lol:
Last edited by desslok on 2008 Apr 16, 19:53, edited 1 time in total.
Post Reply