Last active
December 22, 2022 12:58
-
-
Save yamap55/621b4596226c81a736650c5cc0e33d80 to your computer and use it in GitHub Desktop.
downloadフォルダを綺麗にするスクリプト
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
from datetime import datetime, timedelta | |
import os | |
import os.path | |
import re | |
import shutil | |
IGNORE_FILES = ['old', 'clean_download_directory.bat'] | |
WORK_DIR = os.path.join(os.environ['USERPROFILE'], 'Downloads') | |
OLD_DIR = os.path.join(WORK_DIR, 'old') | |
if not os.path.exists(OLD_DIR): | |
os.mkdir(OLD_DIR) | |
# 現在日付のフォルダを作成 | |
d = datetime.today().strftime("%Y%m%d") | |
target_dir = os.path.join(OLD_DIR, d) | |
if not os.path.exists(target_dir): | |
os.mkdir(target_dir) | |
files = os.listdir(WORK_DIR) | |
for f in files: | |
if f in IGNORE_FILES: | |
continue | |
try: | |
shutil.move(os.path.join(WORK_DIR, f), os.path.join(target_dir, f)) | |
except PermissionError as er: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment