File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ AUTOMATICALLY ORGANISE YOUR ANY FOLDER ACCORDING TO FILE EXTENSIONS
Original file line number Diff line number Diff line change 1+ import shutil , os
2+
3+ file_extensions = []
4+ extensions = ""
5+ extensions_string = ''
6+ path = ''
7+
8+ def FindExtensions (path ):
9+ print ("What folder do you want to organise? Please enter the path below:" )
10+ pathhuman = input ("" )
11+ splitinput = pathhuman .split ("\\ " )
12+ joininput = '\\ \\ ' .join (splitinput )
13+ path = joininput
14+ os .chdir (path )
15+ for filename in os .listdir (path ):
16+ if os .path .isfile (filename ):
17+ filesplit = filename .rsplit ('.' , 1 )
18+ if len (filesplit ) == 2 :
19+ extensions = filesplit [1 ]
20+ extensions_string = str (extensions )
21+ print (filename )
22+ if os .path .exists (str (path + extensions_string )):
23+ shutil .move (filename ,(path + '\\ ' + extensions_string + '\\ ' + filename ))
24+ else :
25+ os .makedirs (path + extensions_string )
26+ shutil .move (filename ,(path + '\\ ' + extensions_string + '\\ ' + filename ))
27+ elif len (filesplit ) == 1 :
28+ if os .path .exists (str (path + "unknown" )):
29+ shutil .move (filename ,(path + "\\ " + "unknown" + "\\ " + filename ))
30+ else :
31+ os .makedirs (path + "unknown" )
32+ shutil .move (filename ,(path + "\\ " + "unknown" + "\\ " + filename ))
33+ print ("Completed!" )
34+
35+
36+
37+ print (FindExtensions (path ))
You can’t perform that action at this time.
0 commit comments