. 1 Import OS 2 Import Re . 3 Import SYS . 4 path R & lt = " C: \ the Users \ liyq \ Desktop \ Python-IMG \ IMG " . 5 the fileList = the os.listdir (path) # folder to be modified . 6 Print ( " before modification: " + STR (the fileList)) # output file contains the file folder . 7 the os.chdir (path) # current working directory to be modified to modify the position of the folder . 8 NUM = . 1 # name variable . 9 for fileName in the fileList: # traversal all files in the folder 10 PAT = " + \.. (JPG | jpeg | JPG) " # regular expression matching file name 11 pattern =re.findall (pat, fileName) # match 12 is Print ( ' pattern [0]: ' , pattern) 13 is Print ( ' NUM: ' , NUM, ' filename: ' , fileName) 14 os.rename (fileName, ( ' name ' + STR (NUM) + ' _ ' + ' 19,970,326 ' + ' _ Hainan China ' + ' . 'Pattern + [ 0 ])) Rename file # 15 NUM = NUM + . 1 # change numbers, proceed to the next one 16Print ( " ----------------------------------------------- ---- " ) 17 sys.stdin.flush () # refresh 18 Print ( " modified: " + str (os.listdir (path))) # output the modified file contains a folder