folder extraction
r.grimm at science-computing.de
r.grimm at science-computing.de
Thu Jan 1 04:23:32 EST 2009
On Dec 30 2008, 4:30 pm, ibpe... at gmail.com 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
More information about the Python-list
mailing list