Full pathed file names as arguments

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
JohnM
Posts: 247
Joined: 08 Jun 2006 11:59
Location: Tasmania, Australia

Full pathed file names as arguments

Post by JohnM »

Hi all,

I am writing a batch script file to process audio/video files and added an icon to the toolbar to run it. The idea being to select the files and then click the button which runs the script which gets all the selected full pathed files as arguments.

This works ok for the most part, however, I've noticed that once the number of files is large enough and the path and/or file names are long enough, the path is removed from the arguments.

Here is a minimal example batch file to demonstrate:
The testit.cmd:
@echo off

echo %*

pause
Here is the command from the toolbar icon:
openwith '"d:\users\john\documents\software\audio visual\mkvtoolnix\testit.cmd"', s
I created the following folder/files:
Long names1.PNG
Long names1.PNG (47.97 KiB) Viewed 1127 times
Clicking my toolbar icon after selecting 1 file gives the expected result:
Long names2.PNG
Long names2.PNG (7.77 KiB) Viewed 1127 times
Clicking my toolbar icon after selecting all the files gives the file names but the paths are gone:
Long names3.PNG
Long names3.PNG (10.68 KiB) Viewed 1127 times
For this example selecting a smaller numbers of files works. The point at which the paths are dropped seems to vary depending on the length of the paths/files and their number. Running the batch from the command line (outside of XY) with the full pathed files as arguments works ok.

Is this expected behaviour? Am I doing something wrong?

Cheers
John
Windows 8.1 x64
XYplorer 22.90.0105 beta

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Full pathed file names as arguments

Post by highend »

What happens when you invoke your script with all those paths (with the amount of where it fails from XYplorer) from the Windows run dialog (WIN+R)?
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Full pathed file names as arguments

Post by highend »

Testing it a bit, the limit of chars is ~2048, after that the cmd shell drops the paths.

Probably the only workaround, use real XY scripting (create the .bat script with the command line call for each selected file), save that bat, execute it (from XY)...
One of my scripts helped you out? Please donate via Paypal

JohnM
Posts: 247
Joined: 08 Jun 2006 11:59
Location: Tasmania, Australia

Re: Full pathed file names as arguments

Post by JohnM »

What happens when you invoke your script with all those paths (with the amount of where it fails from XYplorer) from the Windows run dialog (WIN+R)?
It works fine (I have highlighted the command to make it easier to distinguish the command from the results):
Long names4.PNG
Long names4.PNG (121.6 KiB) Viewed 1117 times
Cheers
Windows 8.1 x64
XYplorer 22.90.0105 beta

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Full pathed file names as arguments

Post by highend »

Ok, then again: Create the script (.bat) file with XYplorers scripting capabilites and execute that.
One of my scripts helped you out? Please donate via Paypal

JohnM
Posts: 247
Joined: 08 Jun 2006 11:59
Location: Tasmania, Australia

Re: Full pathed file names as arguments

Post by JohnM »

I'm not certain I understand what you mean. :eh:

Anyhow, I wrote this:
"Testit : testit"
$file_list = get("SelectedItemsPathNames", "|");
echo "$file_list"
Changed the toolbar button to run it which gives this:
Long names5.PNG
Long names5.PNG (40.25 KiB) Viewed 1113 times
Is that what you meant?
Windows 8.1 x64
XYplorer 22.90.0105 beta

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Full pathed file names as arguments

Post by highend »

No.

Show a real world example for what your .bat file should really do.
Judging from one of your screenshots you want to call mkvtoolnix from it?

If that's true, show a full command call to an example file with all used options
One of my scripts helped you out? Please donate via Paypal

JohnM
Posts: 247
Joined: 08 Jun 2006 11:59
Location: Tasmania, Australia

Re: Full pathed file names as arguments

Post by JohnM »

My batch script (which is actually a bash script) at one point calls:
mkvmerge --identification-format json --identify <input file>
and redirects the json output to a temp file for later analysis by the jq program. It then goes on to call mkvmerge to remux the file with a set of arguments that are built up from parsing the json.

In order that mkvmerge work with long file names, one must prefix the file name with "\\?\", but only if the file name is fully pathed, hence my requirement for full pathed arguments. If the file name is not fully pathed but "too long" (longer than ~255 chars I think) mkvmerge will fail to open the file and my script fails. This happened to me recently.

I just noticed your comment about the 2048 limit. Interesting. Did you try that from XY or the "dos" (ie WIN+R) command line? I just tried it from the bash command line with an argument list that is 3964 chars long with no problems. For me, the problem only occurs when called from XY.

I have worked around the problem by having the toolbar command line pass "<curpath>" as it's first argument and then have the script use that and ignore the paths on the individual file arguments, like so:
openwith '"C:\Program Files\Git\bin\bash.exe" "C:\Program Files\CLI\remux_mkv.sh" "<curpath>"', s
This works ok but is a bit ugly.

Cheers
John
Windows 8.1 x64
XYplorer 22.90.0105 beta

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Full pathed file names as arguments

Post by highend »

Did you try that from XY
Yep. Funnily it should support way more than 2048 bytes (I'm on Windows Server 2019 here), but maybe it's an oversight that more modern Windows OS allow longer argument lists...
I have worked around the problem by having the toolbar command line pass "<curpath>" as it's first argument
This would fail at some point as well (if only enough files are selected) :masked:
One of my scripts helped you out? Please donate via Paypal

JohnM
Posts: 247
Joined: 08 Jun 2006 11:59
Location: Tasmania, Australia

Re: Full pathed file names as arguments

Post by JohnM »

This would fail at some point as well (if only enough files are selected)
Yes you're right. It's ugly and I should have said that it works for now. :whistle:
Windows 8.1 x64
XYplorer 22.90.0105 beta

Post Reply