Working version that supports python3 and handles moving files if the name collides with an existing file
This commit is contained in:
parent
a1885d37a3
commit
6e78b184ee
19
recovery.py
19
recovery.py
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python2
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
source = sys.argv[1]
|
source = sys.argv[1]
|
||||||
destination = sys.argv[2]
|
destination = sys.argv[2]
|
||||||
|
@ -15,11 +16,13 @@ while not os.path.exists(destination):
|
||||||
for root, dirs, files in os.walk(source, topdown=False):
|
for root, dirs, files in os.walk(source, topdown=False):
|
||||||
for file in files:
|
for file in files:
|
||||||
extension = os.path.splitext(file)[1][1:].upper()
|
extension = os.path.splitext(file)[1][1:].upper()
|
||||||
destinationPath = os.path.join(destination,extension)
|
destinationPath = os.path.join(destination,extension)
|
||||||
|
|
||||||
if not os.path.exists(destinationPath):
|
if not os.path.exists(destinationPath):
|
||||||
os.mkdir(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)
|
if os.path.exists(os.path.join(destinationPath,file)):
|
||||||
else:
|
print("WARNING: this file was not copied :" + os.path.join(root,file))
|
||||||
shutil.copy2(os.path.join(root,file), destinationPath)
|
shutil.move(os.path.join(root,file), os.path.join(destination, extension, str(time.time()) + file))
|
||||||
|
else:
|
||||||
|
shutil.move(os.path.join(root,file), destinationPath)
|
||||||
|
|
Loading…
Reference in New Issue