python os.listdir() code example
Example 1: 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
Example 2: os.listdir to array
from os import listdir
from os.path import isfile, join
files = [file for file in listdir(path) if isfile(join(path, file))]