folder extraction

I

ibpet11

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.
 
M

Mike Driscoll

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.

Are you talking about unzipping an archive or walking a directory? If
the former, see the zip module or use the subprocess module to control
an external archiving application. If the latter, see os.walk and the
glob module.

Mike
 
R

r.grimm

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
 
J

John Machin

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))
# put a "break" after the append so that you avoid (a) duplicates [if
the patterns are not mutually exclusive] (b) waste of CPU time
[always]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top