Getting files in a subdirectory in a zip

Discussion in 'Python' started by Echo, Jul 11, 2005.

  1. Echo

    Echo Guest

    What would the best way to get a list of files in a subdirectory in a zip?

    The only thing I can come up with is to extract the zip into a temp
    directory and then just grab the list of files in the subdirectory
    that I need. This way seems very messy to me and I was wondering if
    there are any better ways.

    --
    -Echo
    Echo, Jul 11, 2005
    #1
    1. Advertising

  2. Echo wrote:
    > What would the best way to get a list of files in a subdirectory in a zip?
    >
    > The only thing I can come up with is to extract the zip into a temp
    > directory and then just grab the list of files in the subdirectory
    > that I need. This way seems very messy to me and I was wondering if
    > there are any better ways.
    >


    import zipfile
    z = zipfile.ZipFile('block.zip')
    names = [name[7:] for name in z.namelist()
    if name.startswith('others/')]

    --Scott David Daniels
    Scott David Daniels, Jul 11, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    3,884
    Kristofer Gafvert [MVP]
    Sep 8, 2005
  2. Alex Hunsley
    Replies:
    1
    Views:
    582
    Andrew Thompson
    Sep 16, 2004
  3. moon
    Replies:
    3
    Views:
    8,950
    Thomas Fritsch
    Sep 20, 2005
  4. MoshiachNow
    Replies:
    2
    Views:
    257
    Ilya Zakharevich
    Oct 4, 2006
  5. Bo Yang
    Replies:
    9
    Views:
    286
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page