Quote: Originally Posted by nycblkboy
dir /B /o : D > %1
copy %1 newfile4.txt
The reason this fails is because there is no + signs and the dir command lists each file on it's own line and like richnrockville said the syntax for the copy cmd needs to be "copy 1.txt+3.txt+2.txt newfile4.txt".
This will work for you (also works with text files that have spaces in their name)
for /f "tokens=*" %i in ('dir /b /o:d C:\FolderName') do type "C:\FolderName\%i">> new.txt && echo.>> new.txt
Replace C:\FolderName with the path to the folder that contains the text files.
You need to run this from anywhere in cmd.exe just not in C:\FolderName or you'll end up doubling up because new.txt will also be appended last to the end of itself, unless you specify a full path for new.txt outside of C:\FolderName.
"&& echo.>> new.txt" will start the next text file on a new line in case the preceeding one doesn't end with a blank line. You may want to add a 2nd one of these if you want a blank line between the files but if one file already ends with a blank line then you'll have 2 blank lines in the new file.
No need to use a batch file but if you wanted to then you need to replace the 2 occurrences of %i with %%i
Quote: Originally Posted by jimbo45
This should do what you want. !!!!!
Quote: Originally Posted by richnrockville
The easiest method that I can recommend is to do this.
copy 1.txt+3.txt+2.txt 4.txt
Both of these are correct but they need to be ordered oldest first so that is a hassle to type this up if there's 30 or 40 files. EDIT:
By default "dir /o:d" sorts by "Last Written" (Modified) but you can override this with the /t switch if you want to order by Created or Accessed.