Python Program to Copy a File – 2022

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Copy a File.

Using shutil module

from shutil import copyfile
copyfile("/root/a.txt", "/root/b.txt")
MethodPreserves PermissionsSupports Directory as DestinationCopies MetadataSupports file object
copy()YesYesNoNo
copyfile()NoNoNoNo
copy2()YesYesYesNo
copyfileobj()NoNoNoYes
  • Here we have used the copyfile() method from shutil python package.
  • It takes 2 arguments; source file path and destination file path.

Check out our other python programming examples

Leave a Comment

Your email address will not be published. Required fields are marked *