[Tutor] concatenating files
alan.gauld at btinternet.com
Sat Feb 28 01:52:44 CET 2009
"Bala subramanian" <bala.biophysics at gmail.com> wrote
> I have file1.dat,file2.dat...file 300.dat in one directory. I want
> concatenate all the files in a single file (total.dat) with a
> string "END"
> separating the file contents.
If you are on Linux (or other *nix variant) you may be better off
using the shell...
for f in *.dat
cat $f >> total.dat
echo "END" >> total.dat
Will do it for you.
If you are on Windoze then you need to write a batch file and
then execute it within the for loop so I'd just stick with Python
there. (Or install cygwin :-)
Author of the Learn to Program web site
More information about the Tutor