3

I used to be able to concatenate multiple text files in dos command by order of filename by using this command:

FOR %%1 in (1*.txt) do type %%1 >> combined.txt

Problem is the text files are not combined by the filename order anymore not sure why. So instead of File1.txt, File2.txt and File3.txt they are in order of File3.txt, File1.txt and File2.txt. Any help would be great!

2
  • Does it have to be command prompt, or do you have access to PowerShell? Commented Nov 17, 2016 at 18:42
  • When you say "used to" - when was that? I don't believe DOS/Windows guarantees the return order of directory entries.
    – uSlackr
    Commented Nov 17, 2016 at 19:05

1 Answer 1

1

I too would do this in Powershell in 2016, but this seems to work

for %i in (1*.txt) do echo %i|sort|type %I >combined.txt

(Add second % for use in script file)

2
  • That works until you have 10 files :)
    – DavidPostill
    Commented Nov 17, 2016 at 20:35
  • I don't think that's an issue since he said the files start with 1*. 1 would come first, then 10, 11, 12, etc
    – uSlackr
    Commented Nov 17, 2016 at 21:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .