File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments