Renaming multiple files in a directory using Python
<p>I'm trying to rename multiple files in a directory using this Python script:</p>

<pre><code>import os
path = '/Users/myName/Desktop/directory'
files = os.listdir(path)
i = 1

for file in files:
    os.rename(file, str(i)+'.jpg')
    i = i+1
</code></pre>

<p>When I run this script, I get the following error:</p>

<pre><code>Traceback (most recent call last):
  File "rename.py", line 7, in &lt;module&gt;
    os.rename(file, str(i)+'.jpg')
OSError: [Errno 2] No such file or directory
</code></pre>

<p>Why is that? How can I solve this issue?</p>

<p>Thanks.</p>