-2
I am trying to fetch some files from a folder that brings a pattern in the file name, in case it is 3067-EG3067000076 plus the date, but as they will be daily files the date changes daily and there is also another however, as the date when I download the file comes from the previous day I need to go back one day (so day=1) and when the file is downloaded on Monday I need to go back 3 days so the (days=3) thinking about these variants I developed this code, At first it worked but now it doesn’t work anymore, would anyone have a suggestion of which function to use for the date? or a code suggestion?
import os
import calendar
from datetime import date
from pathlib import Path
data_atual = calendar.day_name[my_date.weekday()]
if data_atual == 'Monday':
teste= 'true'
else:
teste= 'false'
if teste == 'true':
data_atual = datetime.datetime.now() - datetime.timedelta(days=3)
data_atual = (data_atual.strftime("%Y%m%d"))
else:
data_atual = datetime.datetime.now() - datetime.timedelta(days=1)
data_atual = (data_atual.strftime("%Y%m%d"))
os.rename(r'C:\Users\joao\Desktop\convenios\3067-EG3067000076' + str(data_atual) + '.CNV',r'C:\Users\joao\Desktop\convenios2\arquivo.CNV')
The code generates this error:
Nameerror Traceback (Most recent call last) in 4 from pathlib import Path 5 ----> 6 current date = Calendar.day_name[my_date.weekday()] 7 8 if currentdata_== 'Monday': Nameerror: name 'my_date' is not defined
What is the result obtained?
– Augusto Vasques
The first time I tested it worked, now it presents this error. --------------------------------------------------------------------------- Nameerror Traceback (Most recent call last) <ipython-input-1-dae84386bf9f> in <module> 4 from pathlib import Path 5 ---> 6 currentdata_ = Calendar.day_name[my_date.weekday()] 7 8 if currentdata_='Monday': Nameerror: name 'my_date' is not defined
– Gabriel Terribile