[Tutor] os.rename error problem

justin justinstraube at charter.net
Tue Nov 2 08:17:11 CET 2004


Hello,

I know os.rename is pretty easy and straight forward to use but Im trippin up on
something here.  In the interactive prompt I have no problem renaming a file.
Even the file used below. But in a project im working on Im having a some
problems.

#### Start Code

def reName():
    
    new = fileEntry.get()    # Entry widget with the file name
    if new.lower().endswith('.mp3') == False:
        new = new + '.mp3'
        
    old = main_display.get(ACTIVE)  # gets the orig file name from the listbox
    
    for item in pathList:   # Adds the file names to the path
        if os.path.isfile(item + '/' + old) == True:
            old = item + '/' + old 
            new = item + '/' + new 
        else: pass
        
    print 'Source Exits? ' + str(os.path.isfile(old))
    print old
    print 'Destination Exists? ' + str(os.path.isfile(new))
    print new
    os.rename(old, new)

#### End Code

>>> 
Source Exits? True
E:/Phosphorescent/Phosphorescent - ocean_of_storms.mp3
Destination Exists? False
E:/Phosphorescent/Phosphorescent - Ocean of Storms.mp3
Exception in Tkinter callback
Traceback (most recent call last):
  File "D:\PYTHON23\lib\lib-tk\Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "E:\work\Python\ID3edit\v2.0\ID3edit.py", line 71, in reName
    os.rename(old, new)
OSError: [Errno 13] Permission denied
>>> 

Im using Win2k and have checked to see if the file is read-only. Its not and I
have been able to edit the MP3 ID3 tag information without problem. 

Ive read the bit in the 2.3 reference about OSError being raised if the
destination exists, but os.path.isfile(new) says False. 

Can anyone give me a hint as to what Im missing here?

Regards,
Justin



More information about the Tutor mailing list