Skip to content

Commit 016baa9

Browse files
📦 v1.0.4
1 parent 0ac549b commit 016baa9

2 files changed

Lines changed: 74 additions & 77 deletions

File tree

filemover.py

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,78 @@
33
import os
44

55

6-
print(r"""
6+
print(r'''
77
______ __ ____ ____ __ ____ __
88
/ ____/____ ____/ /___ / __ \ ___ _____ / __/___ _____ / /_ / __ \ / /__ __ _____
99
/ / / __ \ / __ // _ \ / /_/ // _ \ / ___// /_ / _ \ / ___// __/ / /_/ // // / / // ___/
1010
/ /___ / /_/ // /_/ // __/ / ____// __// / / __// __// /__ / /_ / ____// // /_/ /(__ )
11-
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.3
11+
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.4
1212
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+
''')
2526

2627
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([])
3637
}
3738

3839

3940
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+
'''
4243
for root in folder_ex:
4344
try:
4445
os.mkdir(root)
45-
print(f"'{root:20}' Created ✔")
46+
print(f'{root:20} Created ✔')
4647
except OSError:
47-
print(f"'{root:20}' Already Exists")
48+
print(f'{root:20} Already Exists')
4849

4950

5051
def get_folder(ext):
51-
"""Returns the Folder that corresponds to the given extension.
52+
'''Returns the Folder that corresponds to the given extension.
5253
5354
Args:
5455
ext (String): The extension of the file.
5556
5657
Returns:
5758
String: The name of the Folder that holds the ext.
58-
"""
59+
'''
5960
for f, ex in folder_ex.items():
6061
if ext in ex:
6162
return f
62-
return "Other"
63+
return 'Other'
6364

6465

6566
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():
6970
# 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)
7876

7977

80-
if __name__ == "__main__":
78+
if __name__ == '__main__':
8179
create_folders()
8280
start()

filemovergui.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,48 @@
44
from os import path
55
from shutil import move
66

7-
print(r"""
7+
print(r'''
88
______ __ ____ ____ __ ____ __
99
/ ____/____ ____/ /___ / __ \ ___ _____ / __/___ _____ / /_ / __ \ / /__ __ _____
1010
/ / / __ \ / __ // _ \ / /_/ // _ \ / ___// /_ / _ \ / ___// __/ / /_/ // // / / // ___/
1111
/ /___ / /_/ // /_/ // __/ / ____// __// / / __// __// /__ / /_ / ____// // /_/ /(__ )
12-
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.3
12+
\____/ \____/ \__,_/ \___/ /_/ \___//_/ /_/ \___/ \___/ \__/ /_/ /_/ \__,_//____/ 1.0.4
1313
14-
|_____________________________________________________________________________________|
15-
| || This Program will move files according to their extension in respective folders.|||
16-
|--------------------------------------------------------------------------------------|
17-
| // Version : 1.0.3 //|
18-
| // Programming : Python3 //|
19-
| // GitHub : pycontributors //|
20-
| // Author : Py-Contributors //|
21-
| // Email : pycontributors@gmail.com //|
22-
| // Telegram : https://t.me/pycontributors //|
23-
| // Website : http://codeperfectplus.herokuapp.com //|
24-
| --------------------------------------------------------------------------------------
25-
""")
26-
14+
| _____________________________________________________________________________________ |
15+
| || This Program will move files according to their extension in respective folders.|| |
16+
| ------------------------------------------------------------------------------------- |
17+
| // Version : 1.0.4 // |
18+
| // Programming : Python3 // |
19+
| // GitHub : py contributors // |
20+
| // Author : Py-Contributors // |
21+
| // Email : pycontributors@gmail.com // |
22+
| // Last Update : July 2022 // |
23+
| // Telegram : https://t.me/pycontributors // |
24+
| // Website : http://codeperfectplus.herokuapp.com // |
25+
| ------------------------------------------------------------------------------------- |
26+
''')
2727

2828
folder_ex = {
29-
"Programming Files": set([".ipynb", ".py", ".java", ".cs", ".js", ".vsix", ".jar"]),
30-
"Compressed": set([".zip", ".rar", ".arj", ".gz", ".sit", ".sitx", ".sea", ".ace", ".bz2", ".7z"]),
31-
"Applications": set([".exe", ".msi"]),
32-
"Pictures": set([".jpeg", ".jpg", ".png", ".gif", ".tiff", ".raw", ".webp", ".jfif", ".ico", ".psd", ".svg", ".ai"]),
33-
"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"]),
34-
"Documents": set([".txt", ".pdf", ".doc", ".xlsx", ".pdf", ".ppt", ".pps", ".docx", ".pptx"]),
35-
"Music": set([".mp3", ".wav", ".wma", ".mpa", ".ram", ".ra", ".aac", ".aif", ".m4a", ".tsa"]),
36-
"Torrents": set([".torrent"]),
37-
"Other": set([])
29+
'Programming Files': set(['ipynb', 'py', 'java', 'cs', 'js', 'vsix', 'jar', 'cc', 'ccc', 'html', 'xml', 'kt']),
30+
'Compressed': set(['zip', 'rar', 'arj', 'gz', 'sit', 'sitx', 'sea', 'ace', 'bz2', '7z']),
31+
'Applications': set(['exe', 'msi', 'deb', 'rpm']),
32+
'Pictures': set(['jpeg', 'jpg', 'png', 'gif', 'tiff', 'raw', 'webp', 'jfif', 'ico', 'psd', 'svg', 'ai']),
33+
'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']),
34+
'Documents': set(['txt', 'pdf', 'doc', 'xlsx', 'pdf', 'ppt', 'pps', 'docx', 'pptx']),
35+
'Music': set(['mp3', 'wav', 'wma', 'mpa', 'ram', 'ra', 'aac', 'aif', 'm4a', 'tsa']),
36+
'Torrents': set(['torrent']),
37+
'Other': set([])
3838
}
3939

40-
4140
def create_folders():
4241
"""Creates the required folders to organize files ('Pictures', 'Videos'...).
4342
"""
4443
for root in folder_ex:
4544
try:
4645
os.mkdir(root)
47-
print(f"'{root:20}' Created ✔")
46+
print('{root:20} Created ✔')
4847
except OSError:
49-
print(f"'{root:20}' Already Exists")
48+
print('{root:20} Already Exists')
5049

5150

5251
def get_folder(ext):
@@ -66,15 +65,15 @@ def get_folder(ext):
6665

6766

6867
def start():
69-
for file in os.listdir():
68+
'''Organize files on the current directory, each to the corresponding folder.
69+
'''
70+
for filename in os.listdir():
7071
# Check it's not filemover.py, a hidden file or a directory
71-
if file != __file__ and file[0] != '.' and path.isfile(file):
72-
try:
73-
_, ex = path.splitext(file)
74-
folder = get_folder(ex)
75-
move(file, folder)
76-
except:
77-
print("Couldn't move file ", file)
72+
if filename != __file__ and filename[0] != '.' and '.' in filename:
73+
ext = os.path.basename(filename).split('.')[-1]
74+
folder = get_folder(ext)
75+
if not os.path.isfile(os.path.join(folder, filename)):
76+
move(filename, folder)
7877

7978

8079
if __name__ == "__main__":

0 commit comments

Comments
 (0)