Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Normally, when I do a copy /b *.data foo in Windows cmd, the *.data files are catenated in the sorted order into the destination file foo. This matches my desired behavior.

However, I just met a curious directory in which this copy /b command will copy the files out of order. The order is not exactly random, but second last file in the sorted order will go first, followed by the remaining files in sorted order.

Is there a way to overcome this strange sorting behavior? More generally, what if I want to copy the files, say, in the reverse order?

share|improve this question
    
What's the name of odd file? –  Joel Coehoorn Dec 2 '10 at 2:52
    
@Joel The filenames are just nnnnnnnn.data where n is a digit and the numbers are consecutive counting from 1. The odd file is always the second last file in the sorted order. Say if I have 5 files, 00000004.data will come out first. –  maverickwoo Dec 2 '10 at 5:20
add comment

1 Answer

up vote 2 down vote accepted

This will concatenate the files in reverse order:

C:\> for /f %i in ('dir /a-d /o-n /b c:\some_dir\*') do @type %i >> c:\another_dir\dest.dat

If there are only a few files, you can list them explicitly:

C:\> copy /b c.dat+a.dat+b.dat dest.dat

Something like this might work in some situations:

C:\> copy /b file*.dat+foo.dat+bar*.dat dest.dat
share|improve this answer
    
I must learn to type faster! What Dennis said. Although type (or more) will only do an ASCII copy and copy /b is binary. –  Rhys Gibson Dec 2 '10 at 4:39
    
@Rhys: I just tested type with binary files and it worked perfectly. –  Dennis Williamson Dec 2 '10 at 4:47
    
Thank you. I was also suspicious on typing a binary file but apparently it works as expected on my Windows 7 machine. –  maverickwoo Dec 2 '10 at 5:22
    
Great. I stand corrected. –  Rhys Gibson Dec 2 '10 at 20:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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