python copy files with time stamp
<p>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. </p>

<pre><code>import shutil
import datetime
shutil.copyfile('C:\\Users\\Documents\\error.log','C:\\Users\\Documents\datetime.now().strftime("%Y%m%d-%H%M%S").log')
</code></pre>

<p>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</p>

<pre><code>import shutil
import datetime
shutil.copyfile('C:\\Users\\Documents\\error.log','C:\\Users\\Documents\' + datetime.now().strftime("%Y%m%d-%H%M%S") + '.log')
</code></pre>

<p><strong>UPDATE</strong>
Forgot to add the second datetime to the statement</p>

<pre><code>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')
</code></pre>

python shutil copyfile