Created
November 29, 2019 17:14
-
-
Save ThomazPom/5bdcfb0177e5824ba81174d02ff8a558 to your computer and use it in GitHub Desktop.
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
import sys | |
from os.path import * | |
from os import * | |
folder_to_class = sys.argv[1] | |
def concat(*args): | |
return ("{}" * len(args)).format(*args) | |
def is_dir_or_has_size(item): | |
return isdir(item) or isfile(item) and getsize(item) > 0 | |
def move_create_rename(item, destination): | |
print(concat(item, "->", destination)) | |
old_path = join(folder_to_class, item) | |
full_dest = join(folder_to_class, destination) | |
new_path = join(full_dest, item) | |
num = 1 | |
if not exists(full_dest): | |
makedirs(full_dest) | |
while exists(new_path): | |
num += 1 | |
new_path = join(full_dest, concat(basename(item), "_", num, splitext(item)[1])) | |
rename(old_path, new_path) | |
hashtable = { | |
'Audios': '.aif,.cda,.mid .midi,.mp3,.mpa,.ogg,.wav,.wma,.wpl', | |
'Discs': 'bin,.dmg,.iso,.toast,.vcd', | |
'Executables': '.apk,.bat,.bin,.cgi,.pl,.com,.exe,.gadget,.jar,.wsf,.sh,.cmd', | |
'Datas': '.csv,.dat,.db,.dbf,.log,.mdb,.sav,.sql,.tar,.xml', | |
'Fonts': '.fnt,.fon,.otf,.ttf', | |
'Images': '.ai,.bmp,.gif,.ico.jpeg,.jpg,.png,.ps,.psd,.svg,.tif,.tiff', | |
'Presentations': '.key,.odp,.pps,.ppt,.pptx', | |
'Programming': '.asp,.aspx,.cer,.cfm,.cgi,.pl,.css,.htm,.html,.js,.jsp,.php,.py,.rss,.xhtml,.c,.class,.cpp,.cs,.h,.java,.sh,.swift,.vb', | |
'Spreadsheets': '.ods,.xlr,.xls,.xlsx,.xlsb,.xlsm', | |
'System': '.bak,.cab,.cfg,.cpl,.cur,.dll,.dmp,.drv,.icns,.ico,.ini,.msi,.sys,.tmp,.inf', | |
'Videos': '.3g2,.3gp,.avi,.flv,.h264,.m4v,.mkv,.mov,.mp4,.mpg,.mpeg,.rm,.swf,.vob,.wmv', | |
'Documents': '.doc,.docx,.odt,.pdf,.rtf,.tex,.txt,.wks,.wps,.wpd', | |
'Archives': '.7z,.arj,.deb,.pkg,.rar,.rpm,.tar,.gz,.z,.zip', | |
'Other': 'not.not', | |
'Links': '.lnk', | |
} | |
exclude = '.part', '.url' | |
for dest, exts in hashtable.items(): | |
exts_array = exts.split(",") | |
for item in listdir(folder_to_class): | |
if splitext(item)[1] in exts_array \ | |
and not splitext(item)[1] in exclude \ | |
and not item.startswith("+") \ | |
and is_dir_or_has_size(join(folder_to_class, item)) > 0: | |
move_create_rename(item, dest) | |
for item in listdir(folder_to_class): | |
if not item in hashtable.keys() \ | |
and not splitext(item)[1] in exclude \ | |
and not item.startswith("+") \ | |
and is_dir_or_has_size(join(folder_to_class, item)) > 0: | |
move_create_rename(item, "Other") | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment