Last active
August 8, 2020 01:37
-
-
Save dannyso16/c1bdad2dd56aa6d1a96a5c1d052c3b64 to your computer and use it in GitHub Desktop.
Windowsのbatファイルとして保存し、好きなフォルダに入れて実行すると過去7日間アクセスしていないファイルをすべてゴミ箱に移す。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM = r""" | |
SET PYTHON_EXE="python.exe" | |
%PYTHON_EXE% %0 %1 | |
PAUSE | |
EXIT | |
""" | |
import os | |
import glob | |
import time | |
import send2trash | |
# TODO: make a log file | |
root_dir = os.path.abspath(os.path.dirname(__file__)) | |
os.chdir(root_dir) | |
files = glob.glob("./**") | |
print(f"{len(files)} files here.") | |
print(files) | |
current_time = time.time() | |
print("Now deleting unused files...") | |
for f in files: | |
name, ext = os.path.splitext(f) | |
if ext == ".bat" or ext == ".py": | |
continue | |
atime = os.path.getatime(f) # last access time | |
ctime = os.path.getctime(f) # last metadata change time | |
mtime = os.path.getmtime(f) # last modification time | |
# delete file which you don't access within a week | |
days_from_last_access = (current_time - atime)/3600/24 | |
if (days_from_last_access >= 7): | |
send2trash.send2trash(f) | |
print(f"--- {f}") | |
print("Completed.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment