import os

counter = 1

outerfilename = "Archive.zip"
ziploop = True

while ziploop == True:
    innerfilename = os.popen('tar -tf ' + outerfilename).read()
    if '' == innerfilename:
        outerfilename = 'flag'
        innerfilename = os.popen('tar -tf ' + outerfilename).read()


    if 'flag/flag.txt' in innerfilename:
        break

    if ('.zip' in outerfilename):
        os.system("unzip -o " + outerfilename)
    elif ('.gz' in outerfilename):
        os.system("rm flag")
        os.system("rm flag.tar")
        os.system("rm flag.zip")
        os.system("gunzip " + outerfilename)
    elif ('.tar' in outerfilename):
        os.system("tar -xf " + outerfilename)
    else:
        os.system("tar -xf " + outerfilename)

    print("NumExtractions: " + str(counter))

    counter = counter + 1

    outerfilename = innerfilename


print("NumExtractions: " + str(counter))

