473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

combined files together

Hi

is there a module to do things like concatenate all files in a given
directory into a big file, where all the files have the same data
formate?
name address phone_no.

or do I have to open each, read from old/write-or-append to new ...

thanks

May 6 '06 #1
4 1291
Gary Wessle wrote:
Hi

is there a module to do things like concatenate all files in a given
directory into a big file, where all the files have the same data
formate?
name address phone_no.

or do I have to open each, read from old/write-or-append to new ...

thanks

There's hardly enough code here to make a module out of this:

combined = open('...', 'wb')
for name in os.listdir(path):
infile = open(os.path.join(path,name), 'rb')
for line in infile:
combined.write(line)

It could be more efficient by reading larger chunks than single lines,
and could be more accurate by closing both input and output files when
done, but you get the point I hope.

On the other hand, if you've got the right OS, you might try something like:
os.system("cat * > combined")

Gary Herron

May 6 '06 #2
Gary Herron <gh*****@islandtraining.com> writes:
Gary Wessle wrote:
Hi

is there a module to do things like concatenate all files in a given
directory into a big file, where all the files have the same data
formate?
name address phone_no.

or do I have to open each, read from old/write-or-append to new ...

thanks

There's hardly enough code here to make a module out of this:

combined = open('...', 'wb')
for name in os.listdir(path):


I need to traverse those files in the order they were created
chronologically. listdir() does not do it, is there a way besides
build a list then list.sort(), then for element in list_of_files open
element?

thanks
infile = open(os.path.join(path,name), 'rb')
for line in infile:
combined.write(line)

It could be more efficient by reading larger chunks than single lines,
and could be more accurate by closing both input and output files when
done, but you get the point I hope.

On the other hand, if you've got the right OS, you might try something like:
os.system("cat * > combined")

Gary Herron

May 7 '06 #3
Gary Wessle wrote:

I need to traverse those files in the order they were created
chronologically. listdir() does not do it, is there a way besides
build a list then list.sort(), then for element in list_of_files open
element?


are the name of the files describing the cration date, or have to rely on the
creation date ?

if the name allows to discriminate the chronology, check glob module.

Eric
May 10 '06 #4
Eric Deveaud <ed******@pasteur.fr> writes:
Gary Wessle wrote:

I need to traverse those files in the order they were created
chronologically. listdir() does not do it, is there a way besides
build a list then list.sort(), then for element in list_of_files open
element?
are the name of the files describing the cration date,


yes
or have to rely on the creation date ?
no


if the name allows to discriminate the chronology, check glob module.
I just tried glob, it does not put out a list with file names sorted.
Eric

May 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Heller | last post by:
"Brad Clements" <bkc@murkworks.com> writes: > Once again I apologize for posting this py2exe question in the ctypes list. ;-) In the long run, this will be the wrong forum. I suggest...
12
by: chipgraphics | last post by:
:confused::confused: I have been on the quest to find a php script that can serve files for downloads and limit the speed at which the file is transfered to the user. I want a faster download...
9
by: Fish Womper | last post by:
I am at best a part time developer of Access databases. I use Access 2.0, as this is all my employer has on its computers. Even so, to use this ancient version requires a fairly convoluted...
6
by: lilcech | last post by:
How can i cobine my image with a html file so i only have one file. The image is used inside the html file so if i delete it or move it, then it wont show up in the html file. :)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.