問題 ; ディレクトリ構造から特定の日付以降に変更されたファイル/フォルダーを見つけて、これらを別の場所にコピーします (タイトルにも明確に記載されています) (:
以下により、
def mod():
"""Find files modified today, given a file path."""
latest = 0
now = time.strftime('%Y-%m-%d', time.localtime())
dir = "/home/y33t/"
for fname in os.listdir(dir):
if fname.endswith(''):
modtime = os.stat(os.path.join(dir, fname)).st_mtime
if modtime > latest:
latest = modtime
out = time.strftime('%Y-%m-%d', time.localtime(latest))
if out == now:
print fname, "has changed today. "
else:
pass
特定の日付に変更されたファイルを特定し、それらを特定の場所にコピーできます。私が達成したいのは、ディレクトリ構造も維持することです。例は次のとおりです。
/testfolder
..somefile1
..somefile2
../testfolder2
....somefile3
....somefile4
等々...
somefile3 が指定された日付に変更され、別の場所に保存するとしますが、保存中はカスケード ディレクトリ構造も維持する必要があります。どうすればエレガントな方法でこれを達成できますか?