shutil.copyfile() Method Syntax

shutil.copyfile(source, destination, *, follow_symlinks = True)

Parameters: 

  • source: A string representing the path of the source file. 
  • destination: A string representing the path of the destination file. 
  • follow_symlinks (optional) : The default value of this parameter is True. If False and source represents a symbolic link then a new symbolic link will be created instead of copying the file.

Note: The ‘*’ in the parameter list indicates that all following parameters (Here in our case ‘follow_symlinks’) are keyword-only parameters and they can be provided using their name, not as positional parameters.

Returns: 

This method returns a string that represents the path of the newly created file.

Python | shutil.copyfile() method

Shutil module in Python helps automate the process of copying and removing files and directories. It comes under Python’s standard utility modules. 

Shutil(short for shell utility) module also provides many functions of high-level operations on files and collections of files.

Similar Reads

What is Shutil.copyfile() method?

The shutil.copyfile() method in Python is used to copy the content of the source file to the destination file. The metadata of the file is not copied. The source and destination must represent a file and the destination must be writable. If the destination already exists then it will be replaced with the source file otherwise a new file will be created....

shutil.copyfile() Method Syntax

shutil.copyfile(source, destination, *, follow_symlinks = True)...

How to Copy a File using Shutil.copyfile() Method in Python

Using shutil.copyfile() method you can easily copy a file to a new file. To use this method just need to mention the source file location and destination file location....

Possible Errors

...

Error Handling

Here we seeing Possible errors occur while using shutil.copyfile() method....