Hello All, I want trying to write a program that searches all the files (recursively) under a given directory in the filesystem for phone numbers in the form of (626) 674-5901 and and then outputting all phone numbers found in a unique format 626-674
(If several numbers have the same office code, there should be only one line of output for that office code.) There are following requirments 1> Search for a pattern in all files in a directory 2> Outputing the result with a unique format ( (626) 674-5901 -> 626-674 ) 3> if the result has new office code (which I am guessing first 3 digits -- 626) -- add to new line if the result has office code already in the list then append ~~~~~~~~ I have generated the regular expression for the pattern .... and have tested it also.... \([0-9]{3}\)\s[0-9]{3}-[0-9]{4} >>> import re >>> p = re.compile('\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}') >>> p = re.compile('\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}') >>> p <_sre.SRE_Pattern object at 0x00C400B8> >>> p <_sre.SRE_Pattern object at 0x00C400B8> >>> print p.match("") None >>> print p.match('(619) 223-1212') <_sre.SRE_Match object at 0x00A3F678> I need options to proceed after finding the match in the files..... ++++++++++++++++++++++++++++++++ I was thinking to find all filenames in the directory using something like .... import os path="C:\\somedirectory" # insert the path to the directory of interest here dirList=os.listdir(path) for fname in dirList: print fname Am I thinking correct ??? ~Thanks Geo
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor