On Dec 30 2008, 4:30 pm, [email protected] wrote:
> how do i get along with this task of extracting multiples folder and
> generating their names individually in a their respective files as
> they were generated.
Hallo,
I hope, that I interpret your question in the right way.
You can use the following function as a starting point to get all
files ending with py or pyc from your working dir.
Invoke getAllFilesOfPatterns(".","*.py *.pyc")
import os
import fnmatch
def getAllFilesOfPatterns( dir ,patterns="*", recursive=True ):
""" patterns must be space separeted string of patterns
e.g: *.pdf *.ps *.html
"""
patterns= patterns.split()
retValue=[]
for path,dirs,files in os.walk(dir):
for file in files:
for pattern in patterns:
if fnmatch.fnmatch( file , pattern ):
retValue.append(os.path.join(path,file))
if not recursive: break
return retValue
Greetings
--
http://mail.python.org/mailman/listinfo/python-list