Python WindowsError: [Error 3] The system cannot find the file specified when trying to rename
<p>I can't figure out what's wrong. I've used rename before without any problems, and can't find a solution in other similar questions.</p>

<pre><code>import os
import random

directory = "C:\\whatever"
string = ""
alphabet = "abcdefghijklmnopqrstuvwxyz"


listDir = os.listdir(directory)

for item in listDir:
    path = os.path.join(directory, item)

    for x in random.sample(alphabet, random.randint(5,15)):
        string += x

    string += path[-4:] #adds file extension

    os.rename(path, string)
    string= ""
</code></pre>
