
import tarfile, sys
#try:
#open tarfile
tar = tarfile.open(sys.argv[1], “r:tar”)
#present menu and get selection
selection = raw_input(“Entern
1 to extract a filen
2 to display information on a file in the archiven
3 to list all the files in the archivenn”)
#perform actions based on selection above
if selection == “1”:
filename = raw_input(“enter the filename to extract: “)
if (filename.endswith(“tar”)):
tar = tarfile.open(filename)
tar.extractall()
tar.close()
print “Extracted in Current Directory”
elif selection == “2”:
filename = raw_input(“enter the filename to inspect: “)
for tarinfo in tar:
if tarinfo.name == filename:
print “n Filename:tt”, tarinfo.name, “n Size:tt”, tarinfo.size, “bytes”
elif selection == “3”:
print tar.list(verbose=True)
#except:
# print “There was a problem running the program”