-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject File Organizer.py
More file actions
88 lines (62 loc) · 2.08 KB
/
Copy pathProject File Organizer.py
File metadata and controls
88 lines (62 loc) · 2.08 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import argparse
import os
import glob
import shutil
parser = argparse.ArgumentParser(description="files organiser")
parser.add_argument("fold_name",help="The gold fold")
args = parser.parse_args()
#images/(jpg, png, jpeg)
image_files = []
for ext in ['*.jpg', '*.jpeg', '*.png']:
image_files.extend(glob.glob(f"**/{ext}", recursive=True))
if image_files:
folder_name = "images"
os.makedirs(folder_name, exist_ok=True)
for file in image_files:
shutil.move(file, folder_name)
#docs/(pdf, docx, md, txt)
docs_files = []
for ext in ['*.pdf', '*.docx', '*.md','*.txt']:
docs_files.extend(glob.glob(f"**/{ext}", recursive=True))
if docs_files:
folder_name = "docs"
os.makedirs(folder_name, exist_ok=True)
for file in docs_files:
shutil.move(file, folder_name)
#code/(py, ipynb, cpp, etc)
code_files = []
for ext in ['*.py', '*.ipynb', '*.cpp','*.etc']:
code_files = [].extend(glob.glob(f"**/{ext}", recursive=True))
if code_files :
folder_name = "codes"
os.makedirs(folder_name, exist_ok=True)
for file in code_files:
shutil.move(file, folder_name)
#data/(csv, json, xlsx)
data_files = []
for ext in ['*.csv', '*.json', '*.xlsx']:
data_files.extend(glob.glob(f"**/{ext}", recursive=True))
if data_files:
folder_name = "datas"
os.makedirs(folder_name, exist_ok=True)
for file in data_files:
shutil.move(file, folder_name)
#others/
other_files = []
for ext in ['*.*']:
image_files.extend(glob.glob(f"**/{ext}", recursive=True))
if other_files:
folder_name = "others"
os.makedirs(folder_name, exist_ok=True)
for file in other_files:
shutil.move(file, folder_name)
images_n = len(image_files)
docs_n = len(docs_files)
code_n = len(code_files)
data_n = len(data_files)
others_n = len(other_files)
print("moved "+images_n+" images")
print("moved "+docs_n+" docs")
print("moved "+code_n+" code files")
print("moved "+data_n+" data files")
print("moved "+others_n+" others")