I would like to copy file with date time stamp. the below code is not working on windows. I am new to python so please help me.
import shutil
import datetime
shutil.copyfile('C:\\Users\\Documents\\error.log','C:\\Users\\Documents\datetime.now().strftime("%Y%m%d-%H%M%S").log')
In your code, you have the code enclosed in the string. You need to run the code out of the string, and combine it with the string. A solution would be
import shutil
import datetime
shutil.copyfile('C:\\Users\\Documents\\error.log','C:\\Users\\Documents\' + datetime.now().strftime("%Y%m%d-%H%M%S") + '.log')
UPDATE Forgot to add the second datetime to the statement
import shutil
import datetime
shutil.copyfile('C:\\Users\\Documents\\error.log','C:\\Users\\Documents\' + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") + '.log')