-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean_downloads_folder
executable file
·39 lines (33 loc) · 1.36 KB
/
clean_downloads_folder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
downloads_folder = os.path.join(os.path.expanduser("~"), "Downloads")
os.chdir(downloads_folder)
def move_file_to(file, destination):
if not os.path.isdir(destination):
os.makedirs(destination)
if os.path.isfile(file):
os.rename(file, os.path.join(destination, file))
for file in os.listdir(downloads_folder):
if file.lower().endswith(
(".png", ".jpg", ".jpeg", ".gif", ".tif", ".tiff", ".bpm", ".svg")
):
move_file_to(file, "Pictures")
elif file.lower().endswith((".mp3", ".wav", ".mpa")):
move_file_to(file, "Music")
elif file.lower().endswith((".hs", ".sh", ".pl", ".py", ".rb", ".jl", ".r", ".js")):
move_file_to(file, "Scripts")
elif file.lower().endswith((".mp4", ".avi", ".mov", ".wmv", ".flv")):
move_file_to(file, "Videos")
elif file.lower().endswith(
(".pdf", ".xls", ".xlsx", ".doc", ".docx", ".ppt", ".pptx")
):
move_file_to(file, "Documents")
elif file.lower().endswith((".fnt", ".fon", ".otf", ".ttf")):
move_file_to(file, "Fonts")
elif file.lower().endswith((".csv", ".dat", ".xml", ".vcf", ".json")):
move_file_to(file, "Data")
elif file.lower().endswith((".zip", ".tar", ".rar", ".7z")):
move_file_to(file, "Compressed")
else:
move_file_to(file, "Misc")