Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Use of glob module in Python code
Program to read and display files in a directory with a particular extension using glob module are discussed in this section
Program list_files.py
Result :
Suppose we want to read a directory for the html files (*.htm) and print the names of the files.
For the following files vhdl1.htm, vhdl2.htm, …, vhdln.htm in a directory
From the python shell we run
>> list_files.py
file in directory vhdl1.htm
file in directory vhdl2.htm
...
file in directory vhdln.htm
#!/usr/bin/python
import glob
import string
import os
import commands
files = glob.glob("*.htm*")
for filename in files:
print "file in directory %s" % (filename)