You must have the simple copying through copy option in windows. As you know Python Copy can do almost anything that you can think of, let’s see how to copy a file using Python. This will help you if you need to write a script of copying data from one place to another in servers where you don’t have access to the user interface.
Let’s take a look at the code.
First we need to import required libraries.
import os |
Now let’s check if the file exists or not
import os |
The output is shown below.
The following function is used to copy the file.
shutil.copy(src,dst) |
“src” stands for source location of the file and “dst” stands for destination.
Following command is used to Copy File with MetaData Information
shutil.copystat(src,dst) |
Let’s first use the simple copy.
import os |
As you can see on the left side that the copy of the file is created.
Copy File with MetaData Information
MetaData information is file permission, modification time etc. The simple copy only copies the data in the file, not the MetaData information. Let’s now copy the metaData info too.
Here is the code.
import os |