I am copy folder and all sub folders inside the main folder using shutil copytree
import shutil
import sys
import os
import re
SOURCE_FOLDER = sys.argv[1]
DESTINATION_FOLDER = sys.argv[2]
def copyDirectory(SOURCE_FOLDER, DESTINATION_FOLDER):
try:
print SOURCE_FOLDER
print DESTINATION_FOLDER
shutil.copytree(SOURCE_FOLDER, DESTINATION_FOLDER)
# Directories are the same
#except:
# print "Not copied"
except shutil.Error as e:
print('Directory not copied. Error: %s' % e)
# Any error saying that the directory doesn't exist
except OSError as e:
print('Directory not copied. Error: %s' % e)
copyDirectory(SOURCE_FOLDER,DESTINATION_FOLDER)
The problem is if the directory exists it throws error
Directory not copied. Error: [Errno 17] File exists: 'destination'
What i want is if directory already exists it want to check all the sub directories and if sub directory also exists it should check all the files in it and it should skip the existing files and copy the new files in that sub directory,If sub direscotry not exists then it should copy that sub directory
Note: Sub directories might be nested(Sub directory of sub directory).
But the above script is not working what should i add to that script?