1

I'm new here and in the world of Python scripting mostly with the arcpy module. I hope you can help me with the trouble that I have.

I'm trying to develop a script to extract or uncompress multiple tar.gz files (I can do it properly) with the condition that if the file into the tar.gz file contains certain name only.

import os, tarfile, glob

ws = "workspace" out = "out workspace"

for tar_file in glob.glob(ws + "/*.gz"):

    tar = tarfile.open(tar_file,"r")

    for member in tar.getmembers():
        if "atribute 1" or "atribute 2" in member.name:    # here i'm failing
            tar.extract(member,out)
            print "%s extracted" %(member)
    tar.close()

I can´t create the condition if. Any idea how can I uncompress only the files with the attributes that I want? I'm trying to do this to extract only some bands of a huge LANDSAT 8 dataset.

1

1 Answer 1

1

it sounds like the attribute is part of the filename?

If so, then all you should do is:

if member.name.find("atribute 1") >=0 or member.name.find("atribute 2")>=: 

This code will check if the attribute is any substring of the file name.

Not the answer you're looking for? Browse other questions tagged or ask your own question.