Why isn't my os.rename working?

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-03-30T00:16:59Z Indexed on 2010/03/30 0:23 UTC
Read the original article Hit count: 768

Filed under:
|

Hi All,

I'm trying to rename some files, but getting a baffling error*. When I run this:

if os.path.isfile(fullPath):
    print 'fmf exists'
    print fullPath
    print newFilePath
    os.rename(fullPath,newFilePath)

I get the following error:

fmf exists
(correct fullPath)
(correct newFilePath, ie. destination)
Traceback (most recent call last):
  File "whatever.py", line 374, in ?
    os.rename(fullPath,newFilePath)
OSError: [Errno 2] No such file or directory

Since I know that the file at fullPath exists, I'm baffled by the error. Of course, newFilePath doesn't exist, because that would be dumb. Any hints?

Thanks! Alex

*Aren't they all?

© Stack Overflow or respective owner

Related posts about python

Related posts about rename