My goal is to create a portable PDF that will execute with the portable navigator I include in the package. The problem is that the navigator's shortcut changes and sets itself relative path correctly, but the arguments on the target field (the PDF file I want the shortcut navigator to open when clicked) remains on the old path.
The challenge is to get the argument path relative to wherever the shortcut is placed (both shortcut and folder with nav and PDF are moved together).
I've tried to set a relative path on the argument in the target field to the Start in field, such as shown in the following example, but it won't work:
Target-> E:\DATA\GoogleChromePortable.exe" .\myPDF.pdf Start in-> E:\DATA
Both myPDF and myShortcut are placed in the same folder (DATA), and the Target and Start in fields become relative according to if changed, their paths adapt to the new location.
As you have found
Windows shortcuts are within limits self-correcting, thus variable results when moved or used with moving targets, often saying "incorrect" delete me !
Thus they should not be used for such movable tasks, it generally occupies more disk space (4,096 bytes) than dragging a small PDF file, so same size as a small batch file which is far simpler to edit.
By far the simplest means is double click myLocalPDF.cmd
start "loadPDF" "%~d0\data\GoogleChromePortable.exe" "file:///%~d0/data/mypdf.pdf"
Which should work as absolute, relative to whichever drive folder it is in, similar for relative folder path you can use `%~dp0 for the folder the .cmd or .bat is starting in.
If you need a command file to adjust relative to its work dir 1st use
cd /d "%~dp0/data" & command to be run at this current work folder location
So in your case if cmd is in root, the line above will adjust to "/data" and then the command is simpler GoogleChromePortable.exe "file:///%~d0/data/mypdf.pdf"
HOWEVER note I still use FULL reference to file:/ as its not good practice to ask for it to take time to seek relative to the exe as the file or exe may be relocated.