This script is used tto copy the file or folder to the given location at any Windows Endpoint.
Please run the script as System User
NOTES:
1. if you want to copy a folder to another location then give the folder path in the COPY_From variable and give the destination path where you want to paste in Paste_To variable. for example:
if you want to copy folder and paste it in another location then just give the value like shown below,
Copy_From = "C:\Users\boss\desktop"
Paste_To = "C:\Users\boss\Documents\backup"
the above will paste all the files and folders in the desktop to the backup folder. if you want to all the files and folders in desktop to be pasted in a specific folder in backup folder then give the value like shown below,
Paste_To = "C:\Users\boss\Documents\backup\desktopbackups"
import os,shutil
Copy_From = itsm.getParameter('Copy_From') # give here the file path or folder path that you want to copy. the datatype should be a string.
Paste_To = itsm.getParameter('Paste_To') # give here the path where you want to paste the copied file or folder. the datatype should be a string.
source= "\\\\".join(Copy_From.split("\\"))
dest= "\\\\".join(Paste_To.split("\\"))
print 'SCRIPT FOR COPYING FILE OR FOLEDER FROM THE SOURCE "%s" TO THE DESTINATION "%s"\n'%(source,dest)
if os.path.exists(source):
if os.path.isdir(source):
print("\t*) You are trying to copy the Directory:")
for root, dirs, files in os.walk(source):
if not os.path.isdir(root):
os.makedirs(root)
for file in files:
rel_path = root.replace(source, '').lstrip(os.sep)
dest_path = os.path.join(dest, rel_path)
if not os.path.isdir(dest_path):
os.makedirs(dest_path)
shutil.copyfile(os.path.join(root, file), os.path.join(dest_path, file))
print '\t\t*) FOLEDER COPIED SUCCESSFULLY TO THE DESTINATION "%s"'%dest
elif os.path.isfile(source):
print("\t*) You are trying to copy the File:")
shutil.copy2(source,dest)
print '\t\t*) FILE COPIED SUCCESSFULLY TO THE DESTINATION "%s"'%dest
else:
print 'ERROR FROM THE SOURCE PATH"%s"'%(source)
Comments