4
Good afternoon ! I need to solve the following scenario in python: I have one or more files . txt in a folder, but I want to return only the files that have the modification date according to the date I want (initial and final), but I’m not able to make this comparison as date with the user input:
import re
import os
from datetime import datetime as dt
#definindo datas
dtEntradaInicial = input('Data inicial: ')
dtEntradaFinal = input('Data final: ')
print(datetime.strptime(dtEntradaInicial, "%d/%m/%y").date())
print(datetime.strptime(dtEntradaFinal, "%d/%m/%y").date())
#testando retorno de data de modificação do arquivo
modificacao = datetime.fromtimestamp(os.path.getmtime('/c:/arquivoteste.txt'))
print('A data de modificação do arquivo é: ', modificacao)
if modificacao >= dtEntradaInicial and modificacao <= dtEntradaFinal:
print('Consegui comparar datas com sucesso!')
dtEntradaInicial
anddtEntradaFinal
are strings. You’re converting strings to date, but you’re not saving anywhere.– fernandosavio