File: ziptools/ziptools/zip-list.py
#!/usr/bin/python """ ============================================================================ zip-list.py - a ziptools command-line client for listing zipfiles. See ziptools' ./_README.html for license, attribution, and other logistics. List the contents of a zipfile, with: <python> zip-list.py [zipfile] The sole optional argument zipfile is the file to list; it is input interactively if omitted, and a ".zip" is appended if missing. <python> is your platform's Python identifier string (e.g., "python3" or "python" on Unix; "python", "py -3", "py", or omitted on Windows). Python's zipfile does most of the work here, but this adds argument prompting when the command line is empty. This could also use zipfile's __main__ interface, by running an os.system command line of the form: python -m zipfile -l somefile.zip. ============================================================================ """ import zipfile, sys from __version__ import showVersion # [1.3] display version number showVersion() # portability RunningOnPython2 = sys.version.startswith('2') RunningOnWindows = sys.platform.startswith('win') if RunningOnPython2: input = raw_input # import os # os.system('%s -m zipfile -l %s' % (sys.executable, sys.argv[1])) if len(sys.argv) == 2: interactive = False thezip = sys.argv[1] else: interactive = True thezip = input('Zipfile to list? ') thezip += '' if thezip[-4:].lower() == '.zip' else '.zip' # the zip bit zipfile.ZipFile(thezip, 'r').printdir() if interactive and RunningOnWindows: input('Press Enter to exit.') # stay open if clicked