Last active
March 27, 2020 20:36
-
-
Save zshanhui/40512cef97f89332764e9833c1504603 to your computer and use it in GitHub Desktop.
Automate Removal of Old Dropbox Screenshots
This file contains hidden or 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
| import os | |
| from datetime import datetime, timedelta | |
| dropbox_screenshot_dir = '/Users/adrienshen/Dropbox/Screenshots' | |
| defaults = { | |
| 'days_since': 30, | |
| } | |
| oldest_date = datetime.now() - timedelta(defaults['days_since']) | |
| def browse_files(): | |
| print('Remove screenshots older than {} days'.format(defaults['days_since'])) | |
| for filename in os.listdir(dropbox_screenshot_dir): | |
| if (filename.split()[0] == 'Screenshot' and is_ancient(filename.split()[1])): | |
| f = os.path.join(dropbox_screenshot_dir, filename) | |
| print('Removing ', f) | |
| os.remove(f) | |
| def is_ancient(file_date): | |
| parsed_date = datetime.strptime(file_date, '%Y-%m-%d') | |
| return parsed_date < oldest_date | |
| def __main__(): | |
| browse_files() | |
| __main__() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment