-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsort
executable file
·26 lines (21 loc) · 858 Bytes
/
fsort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
import os
import os.path
import shutil
import sys
source = sys.argv[1]
destination = sys.argv[2]
while not os.path.exists(source):
source = raw_input('Enter a valid source directory\n')
while not os.path.exists(destination):
destination = raw_input('Enter a valid destination directory\n')
for root, dirs, files in os.walk(source, topdown=False):
for file in files:
extension = os.path.splitext(file)[1][1:].upper()
destinationPath = os.path.join(destination,extension)
if not os.path.exists(destinationPath):
os.mkdir(destinationPath)
if os.path.exists(os.path.join(destinationPath,file)):
print('WARNING: this file was not copied :' + os.path.join(root,file))
else:
shutil.copy2(os.path.join(root,file), destinationPath)