|
3 | 3 | import os |
4 | 4 |
|
5 | 5 |
|
6 | | -print(r""" |
| 6 | +print(r''' |
7 | 7 | ______ __ ____ ____ __ ____ __ |
8 | 8 | / ____/____ ____/ /___ / __ \ ___ _____ / __/___ _____ / /_ / __ \ / /__ __ _____ |
9 | 9 | / / / __ \ / __ // _ \ / /_/ // _ \ / ___// /_ / _ \ / ___// __/ / /_/ // // / / // ___/ |
10 | 10 | / /___ / /_/ // /_/ // __/ / ____// __// / / __// __// /__ / /_ / ____// // /_/ /(__ ) |
11 | | -\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.3 |
| 11 | +\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.4 |
12 | 12 | |
13 | | - |_____________________________________________________________________________________| |
14 | | - | || This Program will move files according to their extension in respective folders.||| |
15 | | - |--------------------------------------------------------------------------------------| |
16 | | - | // Version : 1.0.3 //| |
17 | | - | // Programming : Python3 //| |
18 | | - | // GitHub : pycontributors //| |
19 | | - | // Author : Py-Contributors //| |
20 | | - | // Email : pycontributors@gmail.com //| |
21 | | - | // Telegram : https://t.me/pycontributors //| |
22 | | - | // Website : http://codeperfectplus.herokuapp.com //| |
23 | | - | -------------------------------------------------------------------------------------- |
24 | | -""") |
| 13 | + | _____________________________________________________________________________________ | |
| 14 | + | || This Program will move files according to their extension in respective folders.|| | |
| 15 | + | ------------------------------------------------------------------------------------- | |
| 16 | + | // Version : 1.0.4 // | |
| 17 | + | // Programming : Python3 // | |
| 18 | + | // GitHub : py contributors // | |
| 19 | + | // Author : Py-Contributors // | |
| 20 | + | // Email : pycontributors@gmail.com // | |
| 21 | + | // Last Update : July 2022 // | |
| 22 | + | // Telegram : https://t.me/pycontributors // | |
| 23 | + | // Website : http://codeperfectplus.herokuapp.com // | |
| 24 | + | ------------------------------------------------------------------------------------- | |
| 25 | +''') |
25 | 26 |
|
26 | 27 | folder_ex = { |
27 | | - "Programming Files": set([".ipynb", ".py", ".java", ".cs", ".js", ".vsix", ".jar"]), |
28 | | - "Compressed": set([".zip", ".rar", ".arj", ".gz", ".sit", ".sitx", ".sea", ".ace", ".bz2", ".7z"]), |
29 | | - "Applications": set([".exe", ".msi"]), |
30 | | - "Pictures": set([".jpeg", ".jpg", ".png", ".gif", ".tiff", ".raw", ".webp", ".jfif", ".ico", ".psd", ".svg", ".ai"]), |
31 | | - "Videos": set([".mp4", ".webm", ".mkv", ".MPG", ".MP2", ".MPEG", ".MPE", ".MPV", ".OGG", ".M4P", ".M4V", ".WMV", ".MOV", ".QT", ".FLV", ".SWF", ".AVCHD", ".avi", ".mpg", ".mpe", ".mpeg", ".asf", ".wmv", ".mov", ".qt", ".rm"]), |
32 | | - "Documents": set([".txt", ".pdf", ".doc", ".xlsx", ".pdf", ".ppt", ".pps", ".docx", ".pptx"]), |
33 | | - "Music": set([".mp3", ".wav", ".wma", ".mpa", ".ram", ".ra", ".aac", ".aif", ".m4a", ".tsa"]), |
34 | | - "Torrents": set([".torrent"]), |
35 | | - "Other": set([]) |
| 28 | + 'Programming Files': set(['ipynb', 'py', 'java', 'cs', 'js', 'vsix', 'jar', 'cc', 'ccc', 'html', 'xml', 'kt']), |
| 29 | + 'Compressed': set(['zip', 'rar', 'arj', 'gz', 'sit', 'sitx', 'sea', 'ace', 'bz2', '7z']), |
| 30 | + 'Applications': set(['exe', 'msi', 'deb', 'rpm']), |
| 31 | + 'Pictures': set(['jpeg', 'jpg', 'png', 'gif', 'tiff', 'raw', 'webp', 'jfif', 'ico', 'psd', 'svg', 'ai']), |
| 32 | + 'Videos': set(['mp4', 'webm', 'mkv', 'MPG', 'MP2', 'MPEG', 'MPE', 'MPV', 'OGG', 'M4P', 'M4V', 'WMV', 'MOV', 'QT', 'FLV', 'SWF', 'AVCHD', 'avi', 'mpg', 'mpe', 'mpeg', 'asf', 'wmv', 'mov', 'qt', 'rm']), |
| 33 | + 'Documents': set(['txt', 'pdf', 'doc', 'xlsx', 'pdf', 'ppt', 'pps', 'docx', 'pptx']), |
| 34 | + 'Music': set(['mp3', 'wav', 'wma', 'mpa', 'ram', 'ra', 'aac', 'aif', 'm4a', 'tsa']), |
| 35 | + 'Torrents': set(['torrent']), |
| 36 | + 'Other': set([]) |
36 | 37 | } |
37 | 38 |
|
38 | 39 |
|
39 | 40 | def create_folders(): |
40 | | - """Creates the required folders to organize files ('Pictures', 'Videos'...). |
41 | | - """ |
| 41 | + '''Creates the required folders to organize files ('Pictures', 'Videos'..). |
| 42 | + ''' |
42 | 43 | for root in folder_ex: |
43 | 44 | try: |
44 | 45 | os.mkdir(root) |
45 | | - print(f"'{root:20}' Created ✔") |
| 46 | + print(f'{root:20} Created ✔') |
46 | 47 | except OSError: |
47 | | - print(f"'{root:20}' Already Exists") |
| 48 | + print(f'{root:20} Already Exists') |
48 | 49 |
|
49 | 50 |
|
50 | 51 | def get_folder(ext): |
51 | | - """Returns the Folder that corresponds to the given extension. |
| 52 | + '''Returns the Folder that corresponds to the given extension. |
52 | 53 |
|
53 | 54 | Args: |
54 | 55 | ext (String): The extension of the file. |
55 | 56 |
|
56 | 57 | Returns: |
57 | 58 | String: The name of the Folder that holds the ext. |
58 | | - """ |
| 59 | + ''' |
59 | 60 | for f, ex in folder_ex.items(): |
60 | 61 | if ext in ex: |
61 | 62 | return f |
62 | | - return "Other" |
| 63 | + return 'Other' |
63 | 64 |
|
64 | 65 |
|
65 | 66 | def start(): |
66 | | - """Organize files on the current directory, each to the corresponding folder. |
67 | | - """ |
68 | | - for file in os.listdir(): |
| 67 | + '''Organize files on the current directory, each to the corresponding folder. |
| 68 | + ''' |
| 69 | + for filename in os.listdir(): |
69 | 70 | # Check it's not filemover.py, a hidden file or a directory |
70 | | - if file != __file__ and file[0] != '.' and '.' in file: |
71 | | - try: |
72 | | - _, ex = path.splitext(file) |
73 | | - folder = get_folder(ex) |
74 | | - move(file, folder) |
75 | | - except KeyError as error: |
76 | | - print(error) |
77 | | - print("Couldn't move file ", file) |
| 71 | + if filename != __file__ and filename[0] != '.' and '.' in filename: |
| 72 | + ext = os.path.basename(filename).split('.')[-1] |
| 73 | + folder = get_folder(ext) |
| 74 | + if not os.path.isfile(os.path.join(folder, filename)): |
| 75 | + move(filename, folder) |
78 | 76 |
|
79 | 77 |
|
80 | | -if __name__ == "__main__": |
| 78 | +if __name__ == '__main__': |
81 | 79 | create_folders() |
82 | 80 | start() |
0 commit comments