Do anyone already have code to copy nested files to a flat directory?

Podi prettyboy988-google at yahoo.com
Mon Mar 20 21:05:23 EST 2006


OK, please don't bother. Here is my wheel :-)

import os
import shutil

def CopyFlat(source, target):
    count = 0
    for root, dirs, files in os.walk(source):
        for file in files:
            count += 1
            name = root + '\\' + file
            print '%04d Copying' % count, name,
            if os.access(target + '\\' + file, os.F_OK):
                print 'Already exist and replaced!'
            else:
                print
            shutil.copy(name, target)

    print '%d files copied' % count




More information about the Python-list mailing list