copytree のソース コードを見ると、その核心は次のループです。
for name in names:
if name in ignored_names:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks, ignore)
else:
# Will raise a SpecialFileError for unsupported file types
copy2(srcname, dstname)
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
errors.extend(err.args[0])
except EnvironmentError, why:
errors.append((srcname, dstname, str(why)))
最後に権利を追加するyield
と、ループは機能しますが、時間間隔ではなく、ファイルまたはディレクトリがコピーされるたびに印刷されます(time.sleep
コピー間で発生し、全体に少し時間がかかります;時間間隔ごとに、はい、スレッドが必要になります)。ただし、これにより、より詳細なフィードバックを提供することもできます。たとえば、どのファイルがコピーされたかについてのフィードバックを印刷することができますyield name
(または、 )。yield (srcname, destname)