glob module code example
Example 1: python glob
import glob
print 'Named explicitly:'
for name in glob.glob('dir/subdir/*'):
print '\t', name
print 'Named with wildcard:'
for name in glob.glob('dir/*/*'):
print '\t', name
Example 2: python import filenames that match search
glob.glob('/directory/to/search/search_pattern')
/directory/file.png
/directory/file1.txt
/directory/file2.txt
/directory/file3.png
glob.glob('/directory/*png')
--> ['/directory/file.png', '/directory/filea.png']
files = glob.glob('/directory/*png')
filenames = [files[i].split('/')[-1] for i in range(len(files))]
print(filenames)
--> ['file.png', 'filea.png']
Example 3: python glob subdirectories
import glob
subdirectories = glob.glob("./*/")