[Tutor] Move files to a new directory with matching folder names
questions anon
questions.anon at gmail.com
Wed May 28 05:56:39 CEST 2014
Thanks all,
I got it to work using:
import os
import shutil
destination_prefix="/Data/test/"
source_prefix="/Data/test1/"
for year in range(2011, 2013):
year = str(year)
for month in range(1, 13):
# convert to a string with leading 0 if needed
month = "%02d" % month
source = os.path.join(source_prefix, year, month+"/")
#print source
destination = os.path.join(destination_prefix, year, month+"/")
for files in os.listdir(source):
print files
filepath=os.path.join(source, files)
print "copying", files, "from:", source, "to:", destination
shutil.copy(filepath, destination)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140528/08caa4a8/attachment.html>
More information about the Tutor
mailing list