From a1885d37a3e903b59702d54f87477ad9310c28cd Mon Sep 17 00:00:00 2001 From: Chris Magnuson Date: Wed, 3 Jun 2015 22:28:47 -0400 Subject: [PATCH] Initial commit --- recovery.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 recovery.py diff --git a/recovery.py b/recovery.py new file mode 100644 index 0000000..7e480e1 --- /dev/null +++ b/recovery.py @@ -0,0 +1,25 @@ +#!/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)