November 15th, 2012, 11:47 AM
Writing contents of globbed file
Does anyone have ready code to execute the following steps:
1. glob a set of files (e.g., *.csv)
2. ask for user input to create a file name
3. open a new file with the user-generated name (#2)
4. write the contents of the globbed files into the new file (not the names of the files that were globbed, but the actual contents, e.g., the csv data)
I can get 2 of 4 steps
November 15th, 2012, 11:58 AM
Since, generally, you won't know whether the files are text only, I'd open both the new file and the other files as binary.
outfile=open (<new file name>, 'wb')
for n in lstFiles:
November 15th, 2012, 02:09 PM
That did it. I had the ordering of events wrong, and the embedded .write(f.read()) was they key. Also very concisely written.
Originally Posted by rrashkin