Guest User

Untitled

a guest
Nov 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. import os
  2. import re
  3.  
  4. path_txt = (r'C:UsersusuarioDesktopfiles')
  5.  
  6. name_files = os.listdir(path_txt)
  7.  
  8. for TXT in name_files:
  9. with open(path_txt + '\' + TXT, "r") as content:
  10. search = re.search(r'(([0-9]{4})(/)(([1][9][0-9][0-9])|([2][0-9][0-9][0-9])))', content.read())
  11. if search is not None:
  12. os.rename(os.path.join(path_txt, TXT),
  13. os.path.join("Processos3", search.group(0) + "_" + str(random.randint(100, 999)) + ".txt"))
Add Comment
Please, Sign In to add comment