Page 1 of 1

Full pathed file names as arguments

Posted: 25 Jan 2021 21:41
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
Clicking my toolbar icon after selecting 1 file gives the expected result:
Long names2.PNG
Clicking my toolbar icon after selecting all the files gives the file names but the paths are gone:
Long names3.PNG
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

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:03
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)?

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:15
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)...

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:18
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
Cheers

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:20
by highend
Ok, then again: Create the script (.bat) file with XYplorers scripting capabilites and execute that.

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:33
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
Is that what you meant?

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 22:38
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

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 23:25
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

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 23:31
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:

Re: Full pathed file names as arguments

Posted: 25 Jan 2021 23:42
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: