Page 1 of 1

Hint: Sorting filenames for Montage under Windows

Posted: 2018-06-22T00:21:28-07:00
by whugemann
Problem:
A lot of PDF printers cut photos into horizontal stripes or even tiles. You can extract these sniplets with the help of the xpdf tools and re-combine them with Montage, preferably sending their filenames to a batch file via SendTo. However, the filenames are not sorted by name when sent. So how do you sort the command line parameters?

Solution:

Code: Select all

SETLOCAL EnableDelayedExpansion
::
:: send the command line parameters (i.e. filenames) line-wise to a text file
:: and sort them
DEL list*.txt
For %%i in (%*) DO Echo %%i >> List.txt
SORT list.txt >list2.txt
::
:: you cannot  just hand over the list to Montage via @list2.txt
:: as this does not handle filenames with spaces correctly,
:: thus you have to assemble them in one line again.
:: The usual delimiters have to be blocked.
SET var=
FOR /f "delims=" %%i in (list2.txt) DO (
   SET var=!var! %%i
)
Montage !VAR! -tile 1x -geometry +0+0 "%~dpn1_m%~x1"
::
DEL list*.txt
I hope that helps. Sorting filenames is a common task when handing selected filenames over to the IM command line tools.