1

When you issue the following copy with concatenation command in Windows:

copy /b *.txt elsewhere\all.txt

Is there any way to control the order of source files? A quick test suggests alphabetic sorting, but is there any guarantee?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • 2
    You can control the order of the source files if you specify the order with the copy command. `copy foo.txt + bar.txt + file 3.txt all.txt`. Essentially you will have to programmatically create a string variable with the order of the files and use that variable with the `copy` command. – Squashman Dec 04 '21 at 08:21
  • Honestly, the hassle of writing a piece of logic just to feed a string to `copy`, and the hassle of writing my own file concatenation piece is about the same :) – Seva Alekseyev Dec 04 '21 at 17:28
  • You can get most of the order by just using the `dir` command. It has several different sort orders you can use. – Squashman Dec 04 '21 at 20:41

1 Answers1

3

First, there's no wildcard expansion in cmd like in bash. The command will receive the arguments as-is. In the copy command it passes the wildcard to FindFirstFile which returns files in whatever order the file system presents. In NTFS they're stored in a B-tree structure so if you use English it'll appear to be in alphabetic order, but it won't be like that in other languages or if there are special characters/special collocation rules. On a FAT32 drive files are stored linearly in the file allocation table so files would be listed in the order in that table

See

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • For the record, on FAT32 the file records are not stored in the file allocation table per se; the table stores the blocks that the file occupies, but the directory itself (file names, attributes, starting block, etc). is kept elsewhere. – Seva Alekseyev Dec 04 '21 at 16:34