Do anyone already have code to copy nested files to a flat directory?
Peter Hansen
peter at engcorp.com
Mon Mar 20 21:45:18 EST 2006
Podi wrote:
> 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
A small improvement to the reinvented wheel: use os.sep instead of "\\",
for portability. Better yet, use os.path.join() and avoid the manual
joining of path parts.
-Peter
More information about the Python-list
mailing list