error when renaming files in python
Question: I am trying to rename some files, and i think python is well suited...

the files have the pattern `xxx000xxx000abcde.jpg` (random numbers and letters
followed by a specific letter sequence, say "abcde")

and need to be renamed `xxx000xxx000.jpg` (without the "abcde" at the end)

i tried

    
    
    import os
    for filename in os.listdir("C:/test/temp/jpg"):   
       os.rename(filename, filename[:len(filename)-10]+".jpg")
    

But i get an error "The system cannot find the file specified"

what am i doing wrong ?

Thank you

stack trace:

    
    
    Traceback (most recent call last):
      File "C:\test\rename_jpg\rename_jpg.py", line 4, in <module>
        os.rename(filename, filename[:len(filename)-10]+".jpg")
    WindowsError: [Error 2] The system cannot find the file specified
    Press any key to continue . . .
    


Answer: It's likely caused by the Python script not being in C:/test/temp itself.
Python will look for the filenames in the directory it's being run from,
meaning it will try to rename files that do no exist.

You'd have to add the destination prefix to the filenames:

    
    
    os.rename("C:/test/temp/" + filename, "C:/test/temp/" + filename[:len(filename)-10]+".jpg")
    

