# ! / Usr / bin / Python the env # - * - Coding: UTF-. 8 - * - # Import module regular Import Re # introduced os module, according to the present embodiment use it for file write operations Import os # import log module Import the logging Import logging.handlers Import xlwt Import to xlrd Import MySQLdb Import pymysql DB = pymysql.connect ( " localhost " , " the root " , " 123456 " , " my_db_hanchuan01 " ) #Txt write method DEF writeTxt (Result): # open a file, a representative of additional # F = Open (R & lt './ result_ nothing .txt', 'A', encoding = 'UTF-. 8') F = Open (R & lt ' ./phoneNum01_output.txt ' , ' a ' , encoding = ' UTF-. 8 ' ) # write data Result f.write (Result) # close the file f.close () # traverse the file phone number + gathering method DEF COUNT (dirname = ' D: / tmp / temporary data source / sheet conversion / txtfiles ' ): # ----------------------- regular ----- --------------------------- regular phone number # = the re.compile pattern_mob ( ' . 1 [345 789] \ {D}. 9 ' ) # pattern_mob_plus the re.sub = ( '. 1 [345 789] \ {D}. 9', '. 1 [345 789] \ {D}. 9 +123' ) # --------------------- statistics file ------------------------- ----- variable total # recording file cOUNT = 0 NUM = 0 # records containing the number of the phone number of the file variable for root, dirs, files in os.walk (dirname): # folder under the file number to get each file # len = fileLength (files) # ------------------- number of files in each folder is added to the total number # COUNT = COUNT + fileLength for filename in files: #The path name and file path sake splicing F = Open (dirname + ' / ' + filename, ' R & lt + ' , encoding = ' UTF-. 8 ' ) var1 = (filename) # written to the database file name result = pattern_mob.findall (f .read ()) # Result = pattern_mob_plus.findall (reached, f.read ()) # # pattern_mob.findall Result = Result = Result + "123" Print (Result) Print (type (Result)) Cursor = db.cursor () # using the cursor () method creates a cursor object the cursor #cursor.execute ( "INSERT INTO 00_HEFEI_PHONES VALUES ( '% s',% s)"% (var1, result)) # sql statement performs the db.commit () # -------------- --- crawl phone number, find the file matches the regular characters # IF result: # --------------- statistics file containing phone numbers, if the result is not empty, then Description including mobile phone number, num counter plus 1 # num + = 1 # ------------------- function calls, the phone number written document # writeTxt (str (the Result ) + (dirname) + (filename ) + '\ n') #print ( "the path of the file:" + (dirname) + '/' + (filename) + '\ n') # writeTxt (result + '\ n-') writeTxt # (STR (Result) +' \ n-') Print (type (Result)) # Print (Result) # Print ( "The File name:"+(filename)+'\n') # Print ((filename1) + '\ n-') # main function IF the __name__ == ' __main__ ' : # # call count () h function COUNT () db.Close ()