私は決してそれをpythonでやっていませんが、以下の解決策が思い浮かんできました。これは単純に見えないが、それは動作するはずですし、簡素化することができます(チェックしていない、申し訳ありませんが、コンピュータへのアクセスなしになりました):
def copyDirectoryTree(directory, destination, preserveSymlinks=True):
for entry in os.listdir(directory):
entryPath = os.path.join(directory, entry)
if os.path.isdir(entryPath):
entrydest = os.path.join(destination, entry)
if os.path.exists(entrydest):
if not os.path.isdir(entrydest):
raise IOError("Failed to copy thee, the destination for the `" + entryPath + "' directory exists and is not a directory")
copyDirectoryTree(entrypath, entrydest, preserveSymlinks)
else:
shutil.copytree(entrypath, entrydest, preserveSymlinks)
else: #symlinks and files
if preserveSymlinks:
shutil.copy(entryPath, directory)
else:
shutil.copy(os.path.realpath(entryPath), directory)
は、空の先のサブフォルダですか? –
スニペットは完全に間違っています。 1)ルートディレクトリではなくサブディレクトリ上で 'copytree 'を実行する理由は何ですか? 2) 'd'、' dest'は使われません。 – khachik
@khachik申し訳ありませんが、急いで入力しました。 [2]世話をした。 –