Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 10914bb

Browse files
committed
Add group GUI option instead of specific filetype
1 parent dd91bdd commit 10914bb

File tree

1 file changed

+54
-64
lines changed

1 file changed

+54
-64
lines changed

‎File Mover/fmover.py

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
mode_list = []
1010
sort_list = []
1111

12+
image_list = ['.png', '.jpg', '.jpeg', '.gif']
13+
archive_list = ['.zip', '.rar', '.7z']
14+
textf_list = ['.txt', '.md', '.pdf', '.doc', '.docx']
15+
1216

1317
def get_path(src_or_dst):
1418
folders = {source_folder: destination_folder}
@@ -34,7 +38,7 @@ def main_window(self):
3438
sg.Radio("Disabled", "RADIO1", default=True, key='SBYTD', enable_events=True)]
3539
], title='Sorting Options', title_color='red', relief=sg.RELIEF_SUNKEN)],
3640
[sg.Text("Choose filetype:")],
37-
[sg.Combo(['.zip', '.png', '.txt', '.md'], key='FILETYPE', enable_events=True)],
41+
[sg.Combo(["Archive ('.zip', '.rar'...)", "Image ('.png', '.jpg'...)", "Text ('.txt', '.docx'...)"], key='FILETYPE', enable_events=True)],
3842
[sg.Ok(), sg.Cancel()]]
3943

4044
window = sg.Window('Choose filetype to move', layout, default_element_size=(40, 1))
@@ -85,6 +89,26 @@ def main_window(self):
8589

8690
window.close()
8791

92+
def translate_filetype():
93+
for value in file_type:
94+
if value.startswith("Archive"):
95+
file_type.clear()
96+
for arch in archive_list:
97+
file_type.append(arch)
98+
return str(file_type)
99+
elif value.startswith("Image"):
100+
file_type.clear()
101+
for img in image_list:
102+
file_type.append(img)
103+
return str(file_type)
104+
elif value.startswith("Text"):
105+
file_type.clear()
106+
for txt in textf_list:
107+
file_type.append(txt)
108+
return str(file_type)
109+
else:
110+
pass
111+
88112

89113
def append_mode(mode):
90114
mode_list.append(mode)
@@ -97,19 +121,13 @@ def detect_mode():
97121

98122

99123
def append_file_type(value):
100-
file_type.append(value)
101-
return value
102-
103-
104-
def get_file_type():
105124
if len(file_type) == 1:
106-
return str(file_type)[2:-2]
107-
else:
108-
ft_copy = file_type.copy()
109125
file_type.clear()
110-
ft_copy.pop(0)
111-
file_type.append(str(ft_copy)[2:-2])
112-
return str(file_type)[2:-2]
126+
else:
127+
pass
128+
file_type.append(value)
129+
translate_filetype()
130+
return value
113131

114132

115133
class FileMover():
@@ -122,40 +140,40 @@ def filemover(self, operation, sortby):
122140
raise SystemExit()
123141
elif sortby is None:
124142
for file in os.listdir(get_path('src')):
125-
file_ending = get_file_type()
143+
#file_ending = get_file_type()
126144
is_file_in_curr_dir = os.path.isfile(get_path('dst') + "/" + file)
127-
if file.endswith(file_ending):
128-
result = None
129-
if is_file_in_curr_dir is False:
130-
if operation == "Copy":
131-
result = shutil.copy(get_path('src') + "/" + file, get_path('dst') + "/" + file)
132-
else:
133-
result = shutil.move(get_path('src') + "/" + file, get_path('dst') + "/" + file)
145+
for value in file_type:
146+
if file.endswith(value):
147+
result = None
148+
if is_file_in_curr_dir is False:
149+
if operation == "Copy":
150+
result = shutil.copy(get_path('src') + "/" + file, get_path('dst') + "/" + file)
151+
else:
152+
result = shutil.move(get_path('src') + "/" + file, get_path('dst') + "/" + file)
134153
#if file not in current_dir:
135154
# file_type.pop()
136155

137156
elif sortby == 'Sort by Type':
138157
for file in os.listdir(get_path('src')):
139158
sc = SortCriteria()
140-
file_ending = get_file_type()
141159
is_file_in_dst_dir = os.path.isfile(get_path('dst') + "/" + file)
142160
get_subdir()
143-
#is_file_in_subdir = os.path.isfile(get_subdir()) + "/" + file
144-
if file.endswith(file_ending):
145-
if is_file_in_dst_dir is False and get_subdir() is False:
146-
result = None
147-
if operation == "Copy":
148-
result = shutil.copy(get_path('src') + "/" + file, sc.sortbytype(file_ending) + "/" + file)
149-
else:
150-
result = shutil.move(get_path('src') + "/" + file, sc.sortbytype(file_ending) + "/" + file)
151-
elif is_file_in_dst_dir is False and get_subdir() is True:
152-
result = None
153-
if operation == 'Copy':
154-
result = shutil.copy(get_path('src') + "/" + file, sc.sortbytype(file_ending) + "/" + file)
161+
for value in file_type:
162+
if file.endswith(value):
163+
if is_file_in_dst_dir is False and get_subdir() is False:
164+
result = None
165+
if operation == "Copy":
166+
result = shutil.copy(get_path('src') + "/" + file, sc.sortbytype(value) + "/" + file)
167+
else:
168+
result = shutil.move(get_path('src') + "/" + file, sc.sortbytype(value) + "/" + file)
169+
elif is_file_in_dst_dir is False and get_subdir() is True:
170+
result = None
171+
if operation == 'Copy':
172+
result = shutil.copy(get_path('src') + "/" + file, sc.sortbytype(value) + "/" + file)
173+
else:
174+
result = shutil.move(get_path('src') + "/" + file, sc.sortbytype(value) + "/" + file)
155175
else:
156-
result = shutil.move(get_path('src') + "/" + file, sc.sortbytype(file_ending) + "/" + file)
157-
else:
158-
pass
176+
pass
159177

160178
return sg.PopupOK(f"File transfer successful!\nFile(s) moved to '{get_path('dst')}'")
161179

@@ -185,9 +203,6 @@ class SortCriteria():
185203

186204
def sortbytype(self, ftype):
187205
type_list = [ftype]
188-
image_list = ['.png', '.jpg', '.jpeg', '.gif']
189-
archive_list = ['.zip', '.rar', '.7z']
190-
textf_list = ['.txt', '.md']
191206

192207
# For image files
193208
for type in type_list:
@@ -219,30 +234,5 @@ def sortbytype(self, ftype):
219234
raise SystemExit()
220235

221236

222-
223-
224-
225-
226-
227-
228-
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247237
main_gui = fmGUI()
248238
main_gui.main_window()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /