473,386 Members | 1,741 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,386 software developers and data experts.

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 1313

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

Similar topics

6
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.