[Tutor] Move all files to top-level directory

Dotan Cohen dotancohen at gmail.com
Mon Apr 12 20:21:09 CEST 2010

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
# -*- 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?


Dotan Cohen


More information about the Tutor mailing list