Python is very useful for performing basic tasks like transferring the file from one location to another with few lines of code. The best of using python is that there are already loads of packages that contains already written functions and codes which you can reuse while working on your project.
Also, Python scripts are preferred when it comes to automating boring tasks. Check out this post which helps you in automating the python script to run daily using Windows task scheduler.
Let’s see the code which you can use to transfer the file from one location to another. Here we have used two packages, one is shutil and another is time.
Python Script to transfer the file from one location to another:
#Importing shutil and time package import shutil import time try: print("Copying File") #Provide the path to the file which you want to copy src = "Path-to-file" #Provide path to the destination folder dst = "destination-path-where-we-want-to-save-the-file" #Using shutil's .copy() function which #include source and destination path shutil.copy(src,dst) time.sleep(1) print("Successfully Completed") time.sleep(0.5) except: print("Unsuccessful!! Error Generated") time.sleep(2)
‘
Hope this helps and you can use this Python Script to transfer the file from one location to another. If you need any help, please feel free to reach out via comments below.
Leave a Reply