I don't think the previous answers are cross-platform compatible, as they assume that pathsep / , as noted in some comments. They also ignore subdirectories (which may or may not matter to Pythonpadavan ... were not completely clear from the question). What about:
import os import zipfile z = zipfile.Zipfile('some.zip', 'r') dirs = list(set([os.path.dirname(x) for x in z.namelist()]))
If you really need top-level directories, combine this with agroszer for the last step:
topdirs = [os.path.split(x)[0] for x in dirs]
(Of course, the last two steps can be combined :)
source share