This will print all the subdirectories of the current directory:
print [name for name in os.listdir(".") if os.path.isdir(name)]
I'm not sure what you're doing with split("-")
, but perhaps this code will help you find a solution?
If you want the full pathnames of the directories, use abspath
:
print [os.path.abspath(name) for name in os.listdir(".") if os.path.isdir(name)]
Note that these pieces of code will only get the immediate subdirectories. If you want sub-sub-directories and so on, you should use walk
as others have suggested.