On Mon, Apr 12, 2010 at 1:21 PM, Dotan Cohen <dotanco...@gmail.com> wrote:
> All right, I have gotten quite a bit closer, but Python is now > complaining about the directory not being empty: > > ✈dcl:test$ cat moveUp.py > #!/usr/bin/python > # -*- coding: utf-8 -*- > import os > currentDir = os.getcwd() > > filesList = os.walk(currentDir) > for root, folder, file in filesList: > for f in file: > toMove = root + "/" + f > #print toMove > os.rename(toMove, currentDir) > > ✈dcl:test$ ./moveUp.py > Traceback (most recent call last): > File "./moveUp.py", line 11, in <module> > os.rename(toMove, currentDir) > OSError: [Errno 39] Directory not empty > > > I am aware that the directory is not empty, nor should it be! How can > I override this? > from the docs: os.rename(*src*, *dst*)¶ <http://docs.python.org/library/os.html#os.rename>Rename the file or directory *src* to *dst*. If *dst* is a directory, OSError<http://docs.python.org/library/exceptions.html#exceptions.OSError>will be raised. On Unix, if *dst* exists and is a file, it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if *src* and *dst*are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if *dst* already exists, OSError<http://docs.python.org/library/exceptions.html#exceptions.OSError>will be raised even if it is a file; there may be no way to implement an atomic rename when *dst* names an existing file. Availability: Unix, Windows.It seems what you wan to do is os.rename(toMove, currentDir+f) HTH, Wayne
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor