Skip to content

Commit ce979ae

Browse files
committed
python3 program for rearrange file
1 parent 630c22c commit ce979ae

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

rearrange-files/rearrange-files.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import os
2+
import shutil
3+
4+
class RearrangeFile(object):
5+
def __init__(self):
6+
self.folder_path = os.getcwd()
7+
8+
def all_files(self):
9+
self.list_of_all_files = os.listdir(self.folder_path)
10+
11+
12+
def make_folder_and_return_name(self, foldername):
13+
if os.path.exists(foldername) is False:
14+
os.mkdir(foldername)
15+
else:
16+
foldername = foldername + str(2)
17+
os.mkdir(foldername)
18+
return foldername
19+
20+
21+
def check_folder_existance(self):
22+
for i in range(len(self.list_of_all_files)):
23+
if self.list_of_all_files[i].endswith('.pdf'):
24+
if os.path.exists('pdfs'):
25+
shutil.move(self.folder_path+'/'+self.list_of_all_files[i] ,self.folder_path+'/pdfs' )
26+
else:
27+
os.mkdir('pdfs')
28+
29+
elif self.list_of_all_files[i].endswith('jpg'):
30+
if os.path.exists('jpgs'):
31+
shutil.move(self.folder_path+'/'+self.list_of_all_files[i] ,self.folder_path+'/jpgs' )
32+
else:
33+
os.mkdir('jpgs')
34+
35+
36+
37+
if __name__ == "__main__":
38+
re = RearrangeFile()
39+
re.all_files()
40+
re.check_folder_existance()

0 commit comments

Comments
 (0)