-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrangeFile.py
41 lines (30 loc) · 1.32 KB
/
ArrangeFile.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
41
import pathlib
import shutil
import os
def makedir(input_path, name):
splitted_name = name.split(".")
try:
if splitted_name[len(splitted_name)-1] == '':
if not os.path.exists(input_path+"/unamed"):
os.mkdir(input_path + "/unamed")
print("Making Directory 'unamed'")
print(shutil.copy(input_path +"/"+name, input_path + "/unamed"))
os.remove(input_path + "/" + name)
else:
print(shutil.copy(input_path +"/"+name, input_path + "/unamed"))
os.remove(input_path + "/" + name)
else:
if not os.path.exists(input_path+"/"+splitted_name[len(splitted_name)-1]):
os.mkdir(input_path+"/"+splitted_name[len(splitted_name)-1])
print(shutil.copy(input_path+"/"+name,input_path+"/"+splitted_name[len(splitted_name)-1]))
os.remove(input_path + "/" + name)
else:
print(shutil.copy(input_path + "/" + name, input_path + "/" + splitted_name[len(splitted_name) - 1]))
os.remove(input_path + "/" + name)
except Exception as e:
print(e)
input_path = "/home/suraj"
list_of_name = os.listdir(input_path)
for name in list_of_name:
if os.path.isfile(input_path+"/"+name):
makedir(input_path, name)