Created
June 3, 2012 18:59
-
-
Save jsummerfield/2864628 to your computer and use it in GitHub Desktop.
Clean and organise Downloads
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
#!/usr/bin/env python | |
import os | |
import time | |
SOURCE = '/Users/james/Downloads/' | |
DESTINATION = '/Users/james/Desktop/Stuff/' | |
DIRECTORIES = 'Directories' | |
MTIME_WAIT = 300 # seconds | |
def main(): | |
if not os.path.exists(DESTINATION): | |
os.mkdir(DESTINATION) | |
for name in os.listdir(SOURCE): | |
source = os.path.join(SOURCE, name) | |
if time.time() - os.path.getmtime(source) > MTIME_WAIT: | |
if os.path.isfile(source): | |
_, ext = os.path.splitext(name) | |
ext = ext.replace('.', '') | |
if ext: | |
dest = os.path.join(DESTINATION, ext, name) | |
os.renames(source, dest) | |
elif os.path.isdir(source): | |
dest = os.path.join(DESTINATION, DIRECTORIES, name) | |
os.renames(source, dest) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment