Q:

python list directories only

# List directories under the current working directory.
ls -l | grep "^d"

# List directories under the current working directory and 
# include hidden folders
ls -la | grep "^d"
1
>>> [ name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name)) ]
['ctypes', 'distutils', 'encodings', 'lib-tk', 'config', 'idlelib', 'xml', 'bsddb', 'hotshot', 'logging', 'doc', 'test', 'compiler', 'curses', 'site-packages', 'email', 'sqlite3', 'lib-dynload', 'wsgiref', 'plat-linux2', 'plat-mac']
0

New to Communities?

Join the community