How to force TCC to count in proper numerical order

Dec 26, 2009
21
2
Uranus
I had a bunch of video files I wanted to process:

File 1.mkv
File 2.mkv
File 3.mkv
...
...

...
File 24.mkv

So I did this:

set count=1
for %f in (file*.mkv) do (
mkvpropedit.exe "%f" --edit info --set "title=Video Number %count"
set count=%@eval[%count + 1]
)

It seemed to work, but later, I discovered that all the files, except number 1, were titled wrong. I eventually figured out that TCC doesn't count in proper numerical order when processing files. Instead, it counts like this:

File 1.mkv
File 10.mkv
File 11.mkv
File 12.mkv
File 13.mkv
File 14.mkv
File 15.mkv
File 16.mkv
File 17.mkv
File 18.mkv
File 19.mkv
File 2.mkv
File 20.mkv
File 21.mkv
File 22.mkv
File 23.mkv
File 24.mkv
File 3.mkv

Which for normal file copying/moving is fine and makes no difference. But in my case, it completely screwed everything up.
File 10 is labeled as 2
File 11 is labeled as 3
. . . etc.

Is there a way to force TCC to count in proper numerical order?
 
May 20, 2008
9,910
71
Syracuse, NY, USA
Both FOR and DO return the file names in dictionary order (FOR, no doubt for compatibility with CMD).

Code:
v:\> for %f in (file*) do echo %f
file 1.mkv
file 10.mkv
file 2.mkv

v:\> do f in file* (echo %f)
file 1.mkv
file 10.mkv
file 2.mkv
DIR (OTOH) uses nunerical order.

Code:
v:\> dir /m /k /b file*
file 1.mkv
file 2.mkv
file 10.mkv
There are many ways you could get the file names in numerical order from DIR's output ...

Code:
do f in /p dir /m /k /b file* ( ... use _do_loop in constructing the title )

for /f "usebackq tokens=*" %f in (`dir /m /k /b file*`) do ... [use a count variable in constructing the title]
 
Dec 7, 2009
233
2
Left Coast, USA
Using the "/o:n" switch+argument within the "for" line also seems to sort in correct numerical order. At least it did for a me a few minutes ago (I'm using an older version of TCC, though — things might've changed since then).

Incidentally, the line containing "@eval[]" can be shortened a bit to set count=%@inc[%count].
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,967
53
Albuquerque, NM
prospero.unm.edu
Both FOR and DO return the file names in dictionary order (FOR, no doubt for compatibility with CMD).
I'm pretty sure that FOR and DO, by default, just return files in the same order that they appear in the directory. For NTFS, this is generally ASCIIbetical. For FAT, it's essentially random.
 
May 20, 2008
9,910
71
Syracuse, NY, USA
Using the "/o:n" switch+argument within the "for" line also seems to sort in correct numerical order. At least it did for a me a few minutes ago (I'm using an older version of TCC, though — things might've changed since then).

Incidentally, the line containing "@eval[]" can be shortened a bit to set count=%@inc[%count].
I should have known about /o:n ... works with DO also.

Even shorter (and faster):

Code:
set /a count+=1
 

samintz

Scott Mintz
May 20, 2008
1,369
12
Solon, OH, USA
Alternatively, you can just use a counted do loop.
Code:
do f=1 to 24 (mkvpropedit.exe "file %f" --edit info --set "title=Video Number %f")
if there are gaps in the numbers then you can check for existence before executing the command.
Code:
do f=1 to 24 (if isfile "file %f" mkvpropedit.exe "file %f" --edit info --set "title=Video Number %f")