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!

  • Does it have to be command prompt, or do you have access to PowerShell? – Robbie Crash Nov 17 '16 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 Nov 17 '16 at 19:05
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)

|improve this answer|||||
  • That works until you have 10 files :) – DavidPostill Nov 17 '16 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 Nov 17 '16 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.