1

このスクリプトに基づいて:

 #!/usr/bin/python

# run by crontab
# removes any files in /tmp/ older than 7 days

import os, sys, time
from subprocess import call

now = time.time()
cutoff = now - (7 * 86400)

files = os.listdir("/tmp")
for xfile in files:
        if os.path.isfile( "/tmp/" + xfile ):
                t = os.stat( "/tmp/" + xfile )
                c = t.st_ctime

                # delete file if older than a week
                if c < cutoff:
                        os.remove("/tmp/" + xfile)

変更時間に基づいてパス内のファイルを削除できますが、変更時間に基づいて他のフォルダー内のフォルダーを削除するにはどうすればよいでしょうか?

これは、メイン フォルダーに多くのフォルダーがあることを意味しますが、メイン フォルダーとサブフォルダーを保持し、変更時刻が特定の時刻よりも古いフォルダーのみを削除する必要があります。

4

1 に答える 1