os.listdir directories only code example
Example 1: list only directories
# 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"
Example 2: python os.listdir
#!/usr/bin/python
import os, sys
# Open a file
path = "/var/www/html/"
dirs = os.listdir( path )
# This would print all the files and directories
for file in dirs:
print file