List of files to be opened

Carl J. Van Arsdall cvanarsdall at mvista.com
Wed Jan 25 19:18:43 EST 2006


yawgmoth7 wrote:
> Hello, I am currently writing a script that requires a few different
> files to be opened, and examined. What I need to be able to do is use
> something like:
>
> filelist = os.system("ls")
> <Some way to open the file list and read each file one by one here
>   

There are a number of ways you can do this, one method would be to do a loop

for file in os.popen('ls').readlines():
  if os.path.isfile(file):
    open(file)  #or whatever

there's also an os.listdir i believe, check python's documentation

>
> I cannot think of a way to do this, I could put them in a list of
> something of the sort. But that still does not solve the problem of
> opening them one by one.
>
> Thanks for all the advice and help.
> --
> gurusnetwork.org
> Gurus'Network - Are you a guru?
>   


-- 

Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list