0

Me again... I wanted to see if they could help me with a little problem in Python. I have a script that is responsible for analyzing text files. I need to get Python to analyze the last text file that is created in a directory. Is there any way to make the script run by changing the value of a variable, by the name of the last created file? I attach the script to make it easier to understand. Thank you What you have to change the name, is the text file that is in line 2

import re
with open("SPAM Nuevo Lead.txt ","r") as f:
    for l in f:
        nombre = re.search(r"Nombre:(.*)", l)
        if nombre:
            valor_nombre = nombre.group(1)
            #print(valor_nombre)

        telefono = re.search(r"Telefono:(.*)", l)
        if telefono:
            valor_telefono = telefono.group(1)
            #print(valor_telefono)

        email = re.search(r"Email:(.*)", l)
        if email:
            valor_email = email.group(1)
            #print(valor_email)
Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
  • You can check files last access timestamp and figure out which file is the newest – matiit Jan 05 '18 at 15:15
  • Thank you very much! And sorry for not realizing that there was an issue exactly the same, when I searched, I did not find it then I opened a new topic. – Santiago Ruffino Jan 08 '18 at 13:48

0 Answers0