0

I'm trying to rename a file using Python code that is in Downloads folder but I keep receiving below error. I cannot find the absolute path.

FileNotFoundError: [WinError 3] The system cannot find the path specified: '~/Downloads/Test.xlsx' -> 'Test_2023-01-25 14:04:51.552908.xlsx'

Here is the code:

import os
import datetime
dt = str(datetime.datetime.now())

newname = 'Test_'+dt+'.xlsx'
os.rename('~/Downloads/Test.xlsx', newname)

Appreciate all the help I can get. Thank you very much in advance.

JoeCastro
  • 59
  • 5
  • This may be useful https://stackoverflow.com/questions/35851281/python-finding-the-users-downloads-folder . The "~" symbol is throwing it off. – Marc Morcos Jan 25 '23 at 05:31
  • Thanks @MarcMorcos, I checked this article earlier and I have to test each answers. – JoeCastro Jan 25 '23 at 05:43
  • can't still figure out the script to resolve the issue. maybe its just me, tried possible solution from this article https://stackoverflow.com/questions/35851281/python-finding-the-users-downloads-folder – JoeCastro Jan 25 '23 at 09:05
  • If you dont need this to be general you can put the true absolute path yourself. On windows it would be something like C:/Users/yourusername/Downloads – Marc Morcos Jan 25 '23 at 15:10

0 Answers0