119 of 151 menu

The copy method of the shutil module

The copy method of the shutil module copies a file while preserving its access mode. The first parameter of the method specifies the path to the source file, and the second parameter specifies the destination path of the new file.

The third optional parameter specifies how to work with symbolic links (by default follow_symlinks=True).

Syntax

import shutil shutil.copy(where do we copy from, where do we copy to, [mode for symbolic links])

Example

Let's copy the file file1.txt to the file file2.txt:

import shutil shutil.copy('file1.txt', 'file2.txt')

See also

  • method copy2 of module shutil,
    which copies a file with metadata
  • method copytree of module shutil,
    which recursively copies a folder
  • method path.isfile of module os,
    which checks the existence of a file
  • method move of module shutil,
    which recursively moves a file or directory
  • method makedirs of module os,
    which creates folders
  • method mkdir of module os,
    which creates one folder
  • method rmdir of module os,
    which moves or deletes an empty folder
  • method remove of module os,
    which deletes the file
  • method getcwd module os,
    which returns the current working directory
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline