Python Script for Running a Python Program over Different Filesinthe Directory

Shalen chhabra shalen_itbhu at hotmail.com
Sat Mar 13 08:01:17 EST 2004


Thanks to all who responded: But my problem still remains unsolved:
I can do for sure this:

import os

for f in os.listdir('/path/to/dir'):
	<do stuff to f>


But lets pay attention to my original post:

I said I want to run a python program.

For example: If i want to run a python program like this:

instead of <do stuff to f>

python program.py file1

If I write this in place of <do stuff to f> it gives me a syntax error. How 
can I embed this information of running a python program over all the files, 
iteratively using a python script.

Got it?
Now please suggest if there is something in python for this?
Thanks
Shalen


>From: "Ivo" <Spam at ivonet.nl>
>To: python-list at python.org
>Subject: Re: Python Script for Running a Python Program over Different 
>Filesinthe Directory
>Date: Sat, 13 Mar 2004 11:33:13 +0100
>
>import glob,os
>filelist=glob.glob('/folder here/*') # retrieve your listing.
>for file in filelist:
>     if os.path.isfile(file):
>       <do your stuff here>
>--
>Cheerz,
>Ivo.
>http://IvoNet.nl
>
>
>============================
>"Shalen chhabra" <shalen_itbhu at hotmail.com> wrote in message
>news:mailman.351.1079166133.19534.python-list at python.org...
> > Hey,
> >
> > Can anyone give me a snippet for running a python program over all the
>files
> > in the directory.
> > For ex:  I have ten files in a directory and I want to run a python
>program
> > against all of these files, I wish to do the same using another python
>code
> > instead of running each of these files one by one, which would be
>cumbersome
> > giving the argv of each file every single time.
> >
> > This can be easily done using a shell script but I just wanted to have a
> > flavour of python for this.
> >
> > Thanks
> > Shalen
> >
> > _________________________________________________________________
> > Fast. Reliable. Get MSN 9 Dial-up - 3 months for the price of 1!
> > (Limited-time Offer)
>http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/
> >
> >
>
>
>--
>http://mail.python.org/mailman/listinfo/python-list

_________________________________________________________________
Learn how to help protect your privacy and prevent fraud online at Tech 
Hacks & Scams. http://special.msn.com/msnbc/techsafety.armx





More information about the Python-list mailing list