Wednesday, October 12, 2011

Python File Globbing

#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Date: 12-Oct-2011
#Purpose: Demonstrating File Globbing using python
import glob

find = raw_input("Enter the file or directory to be searched : ")

result = glob.glob(find)

if result:
 for element in result:
  print element
 print "The total number of files are : ", len(result)
else:
 print "No match found"

#END

Output

bala@bala-laptop:~/python$ python glob.py
Enter the file or directory to be searched : /home/bala/Pictures/*.jpeg
/home/bala/Pictures/dslInside.jpeg
/home/bala/Pictures/RSA_Thumbnail.jpeg
/home/bala/Pictures/dslDMZ.jpeg
/home/bala/Pictures/dslOutside.jpeg
/home/bala/Pictures/python.jpeg
The total number of files are :  5
bala@bala-laptop:~/python$

No comments:

Post a Comment