File tree 3 files changed +26
-5
lines changed
3 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 1
1
2
2
import os
3
- import shutil
3
+
4
4
filelist = []
5
5
6
6
#path of the the folder you want to sort
7
- src = ( r'C:\Users\'UserName' \ Downloads ')
7
+ src = "in/"
8
8
9
9
10
10
extOnly = set ()
30
30
for file in filelist :
31
31
extFinal = file .split ('.' )
32
32
try :
33
- os .rename (file , extFinal [1 ] + "_Files/" + file )
34
- except ( OSError , IndexError ) :
35
- continue
33
+ os .rename (src + file , extFinal [1 ] + "_Files/" + file )
34
+ except Exception as e :
35
+ print ( e )
Original file line number Diff line number Diff line change
1
+ rm -rf out/
2
+ mkdir out
3
+ touch in/test.txt
4
+ touch in/test2.txt
5
+ touch in/test.py
6
+ touch in/test2.py
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ indir = "in/"
4
+ outdir = "out/"
5
+
6
+ files = set ()
7
+ for file in os .listdir (indir ):
8
+ if "." in file :
9
+ files .add (file )
10
+
11
+ for e in [e .split ("." )[1 ] for e in files ]:
12
+ if not os .path .exists (outdir + "/" + e ): os .mkdir (outdir + "/" + e )
13
+
14
+ for f in files :
15
+ os .rename (indir + f , outdir + str (f .split ("." )[1 ])+ "/" + f )
You can’t perform that action at this time.
0 commit comments