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