Is there a way to return a list of all the subdirectories in the current directory in Python?
I know you can do this with files, but I need to get the list of directories instead.
Is there a way to return a list of all the subdirectories in the current directory in Python?
I know you can do this with files, but I need to get the list of directories instead.
You can get the list of subdirectories (and files) in Python 2.7 using os.listdir(path)
Much nicer than the above, because you don't need several os.path.join() and you will get the full path directly (if you wish), you can do this in Python 3.5+
This will give the complete path to the subdirectory. If you only want the name of the subdirectory use
f.name
instead off.path
https://docs.python.org/3/library/os.html#os.scandir
use a filter function
os.path.isdir
overos.listdir()
something like thisfilter(os.path.isdir,[os.path.join(os.path.abspath('PATH'),p) for p in os.listdir('PATH/')])