Strange exceptions raised by os.renames and shutil.copytree

drifty at my-deja.com drifty at my-deja.com
Sat Jan 13 01:09:24 EST 2001


I am writing a program that involves the step of moving a directory in
its entirety (although that entirety is a single level directory) into a
storage directory.  So if the directory is 'C:\\spam', I am trying to
move it to 'C:\\Storage\\Spam' .  But the problem is that the two ways I
am trying to do this keep throwing me error messages (albeit not
consistently).

First, I tried


def mvDir (src, dst):
    shutil.copytree(src, dst)
    shutil.rmtree(src)


But I get OSError [errno 2] while performing the shutil.copytree() step,
saying that the dst directory does not exist.  But it is supposed to not
exist!  Copytree requires that it not exist!

The second way I tried was using os.renames(), but that raised OSError
[errno 13].  Now I realize that normally this would be resolved by
making sure that all files in the directory being renamed were closed,
but the problem is that I don't have any files open from the directory.
 The only thing the program has done to the source directory up to that
point is os.listdir() and os.path.isdir() on the directory.

Now all of this is being tried under Windows 98, so I have no idea if
this is Windows-specific or not.  I also don't understand why sometimes
the errors are not thrown.  I can just uncomment one of the commands and
it will work.  But try again and it raises an error.

Any help would be greatly appreciated since I am stumped on this and I
would like to be able to move beyond this point in my program.

-Brett


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list