473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Process multiple files

Funny,

I'm just doing exactly this:

import os

def main():
dataFolder = 'data/'
fileList = os.listdir(dataFolder)
for file in fileList:
inFile = open(dataFolder + file, 'r')
print 'read inFile & do something useful here'

Clear as an... egg?

Cheers.
Paul.

Den 14. april. 2008 kl. 14.36 skrev Doran, Harold:
Say I have multiple text files in a single directory, for illustration
they are called "spam.txt" and "eggs.txt". All of these text files are
organized in exactly the same way. I have written a program that
parses
each file one at a time. In other words, I need to run my program each
time I want to process one of these files.

However, because I have hundreds of these files I would like to be
able
to process them all in one fell swoop. The current program is
something
like this:

sample.py
new_file = open('filename.txt', 'w')
params = open('eggs.txt', 'r')
do all the python stuff here
new_file.close()

If these files followed a naming convention such as 1.txt and 2.txt I
can easily see how these could be parsed consecutively in a loop.
However, they are not and so is it possible to modify this code such
that I can tell python to parse all .txt files in a certain directory
and then to save them as separate files? For instance, using the
example
above, python would parse both spam.txt and eggs.txt and then save 2
different files, say as spam_parsed.txt and eggs_parsed.txt.

Thanks


--
http://mail.python.org/mailman/listinfo/python-list
Jun 27 '08 #1
0 1317

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

Similar topics

6
3170
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
2
2421
by: Jeffrey Palermo, MCAD.Net | last post by:
I have some classes that control file processing in c#. The files come from a mainframe and may take some time for each to process. I use the Threadpool to process multiple files at once. Each...
6
2162
by: gizmo | last post by:
I have a requirement to initiate more than one instance of an application using the filenames. (the example below will start two instances of MS Word). My problem is that I need to kill each...
3
4380
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
0
1675
by: vasikaran | last post by:
Hi , i hava one ftp script in batch file programming , ftp script is working fine.. but my is i dont know how much files and what are files avaiulable in remote folder ,,,, if any errors or...
1
2053
by: Doran, Harold | last post by:
Say I have multiple text files in a single directory, for illustration they are called "spam.txt" and "eggs.txt". All of these text files are organized in exactly the same way. I have written a...
0
134
by: Robert Bossy | last post by:
Doran, Harold wrote: Hi, It seems that you need glob.glob() : http://docs.python.org/lib/module-glob.html#l2h-2284 import glob for txt_filename in...
4
2244
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
7
9385
by: dieter | last post by:
Hi, Overview ======= I'm doing some simple file manipulation work and the process gets "Killed" everytime I run it. No traceback, no segfault... just the word "Killed" in the bash shell and...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.