-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_episodes.py
35 lines (25 loc) · 976 Bytes
/
sort_episodes.py
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
import os
import fnmatch
import shutil
directory = input("enter your directory: ")
''' for pattern input the same word in all files.
if there is other characters before or after the pattern use *
for example: *pattern* '''
pattern = input("enter the pattern: ")
def find_match():
i = 0
try:
for file_name in os.listdir(directory):
if fnmatch.fnmatch(file_name.lower().replace(" ", "."),
pattern.lower().replace(" ", ".")):
i += 1
# creating the destination folders
dst = os.path.join(directory, str(i))
os.makedirs(dst)
src = os.path.join(directory, file_name)
# moving the source files to the destination folders
shutil.move(src, dst)
print("The operation was successful :)")
except:
print("The operation was unsuccessful")
find_match()