Skip to content

Commit fa7eb80

Browse files
Merge pull request #461 from aveetron/master
added python3 program for rearranging files on your computer.
2 parents 630c22c + 28075c8 commit fa7eb80

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

rearrange-files/rearrange-files.py

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

0 commit comments

Comments
 (0)