-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule-1.py
40 lines (23 loc) · 1.2 KB
/
Module-1.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
36
37
38
39
40
import os
def main():
current_folder = os.getcwd()
my_folder_path = os.path.join(current_folder, 'my_folder')
distination_folder_txt = os.path.join(my_folder_path , 'text_only')
distination_folder_jpg = os.path.join(my_folder_path, 'jpg_only')
distination_folder_py = os.path.join(my_folder_path, 'py_only')
if not os.path.exists(distination_folder_txt):
os.makedirs(distination_folder_txt)
if not os.path.exists(distination_folder_jpg):
os.makedirs(distination_folder_jpg)
if not os.path.exists(distination_folder_py):
os.makedirs(distination_folder_py)
for folder ,subfolder , filenames in os.walk(my_folder_path):
for files in filenames:
if os.path.splitext(files)[-1]==".txt":
os.rename(os.path.join(folder , files),f"{distination_folder_txt}/{files}")
if os.path.splitext(files)[-1]==".py":
os.rename(os.path.join(folder , files),f"{distination_folder_py}/{files}")
if os.path.splitext(files)[-1]==".jpg":
os.rename(os.path.join(folder , files),f"{distination_folder_jpg}/{files}")
if __name__ == '__main__':
main()