I know there has been loads of questions about that but I've tried every possible solution but can't get rid of the backslash on my windows path. I'm generating PDF releases names list of those that with an update date greater than Sep'21 into a list(pdfs_test): My function looks like that:
def loc_folder_pdfs_date(folder_location):
path = os.getcwd()
dir_list = os.listdir(folder_location)
for file in dir_list:
if file.endswith('.pdf'):
full_name= folder_location + file
c_ti = time.ctime(os.path.getctime(full_name))
m_ti = time.ctime(os.path.getmtime(full_name))
T_stamp = time.strftime("%Y-%m-%d", time.strptime(m_ti))
if T_stamp > "2021-09-01":
PDF_releases.append(file)
return PDF_releases
location = str(r'C:\Users\USER\LOC\LOC_SUB\')
pdfs_test = loc_folder_pdfs_date(location)
getting error for the first file on the folder: FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\Users\USER\LOC\LOC_SUB\\file.pdf'
tried:
location = location .replace("\\", "\")
#or:
location = str(r'C:\Users\USER\LOC\LOC_SUB')
which is just SyntaxError: EOL while scanning string literal