0
過去24時間の新しいファイルまたは更新されたファイルのみを新しいフォルダに移動するスクリプトを作成しようとしています。これまで一般的にファイルを移動するためのスクリプトを作成しましたが、どのようなリードや提案も高く評価されます。新しいファイルまたは更新されたファイルのみを移動する方法は?
import os, shutil
source = os.listdir('C:\Users\Student\Desktop\FolderA')
destination = 'C:\Users\Student\Desktop\FolderB'
os.chdir('C:\Users\Student\Desktop\FolderA')
for files in os.listdir("C:\Users\Student\Desktop\FolderA"):
if files.endswith(".txt"):
src = os.path.join("C:\Users\Student\Desktop\FolderA",files)
dst = os.path.join(destination,files)
shutil.move(src,dst)
ここでは、ファイルの作成日時を得るのを助けることができ質問です:http://stackoverflow.com/questions/237079/how-to-get-file-creation-modification-date-times-inは-python 作成日で、現在の日付と比較することができます。 –
(1)同じコードでハードコーディングされたリテラル 'FolderA'パスを4回繰り返さないでください。 (2) 'os.stat(filename).st_mtime'を使って、ファイルの最終更新タイムスタンプを取得します。 – jez
[Pythonでファイルを最後に修正した時刻を取得するにはどうすればよいですか?](http://stackoverflow.com/questions/375154/how-do-i-get-the-time-a-file-was -last-modified-in-python) –