Skip to content

Instantly share code, notes, and snippets.

@yamap55
Last active December 22, 2022 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yamap55/621b4596226c81a736650c5cc0e33d80 to your computer and use it in GitHub Desktop.
Save yamap55/621b4596226c81a736650c5cc0e33d80 to your computer and use it in GitHub Desktop.
downloadフォルダを綺麗にするスクリプト
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