In my experience with copy /b, it takes the files in directory order, not sorted...
Actually Windows/CMD has got a little smarter over the years, it does now sort it first
This is not true. From the semi-authoritative source of Raymond Chen's blog:
https://blogs.msdn.microsoft.com/oldnewthing/20140304-00/?p=1603It depends on the filesystem in use. On NTFS, it will effectively sort alphabetically but you shouldn't rely on this behaviour. Cameras usually use FAT32 or exFAT where the files will be in the order they are created. If you always shoot in order, never delete on the camera and always reformat after transferring, the files will be order. If you do delete on the camera, the old empty directory entry might be filled first with the newest file which will put the files out of order.
Here's my test on FAT32 and exFAT using Maalobs's example but creating the files out of order:
for /l %i in (5,1,9) do @echo %i > %i.txt
for /l %i in (0,1,4) do @echo %i > %i.txtThe files are out of order on the disk:
D:\outOForder>dir /b
5.txt
6.txt
7.txt
8.txt
9.txt
0.txt
1.txt
2.txt
3.txt
4.txtUsing
copy + will copy them out of order:
D:\outOForder>copy ?.txt merged.txt
5.txt
6.txt
7.txt
8.txt
9.txt
0.txt
1.txt
2.txt
3.txt
4.txt
1 file(s) copied.The resulting merged file will be out of order:
D:\outOForder>type merged.txt
5
6
7
8
9
0
1
2
3
4I haven't written batch files for a long time but here is an alternate solution that seems to work:
FOR /F "usebackq" %i IN (`dir ?.txt /b /on`) DO type %i >> mergedGOOD.txt
D:\outOForder>type mergedGOOD.txt
0
1
2
3
4
5
6
7
8
9The
usebackq setting enables the use of the
dir ?.txt /b /on command to generate a sorted list of files.
I am wary of claiming this as a definitive solution since the
type command seems to be used for encoding conversion and other things that might ruin binary files. I made a cursory test with two binary files and it seemed to work just like
copy /b +.
If I had to do this type of operation myself, I would use
dir /b /on to create an ordered list of files and use Notepad to compose the
copy /b + command.