127 of 151 menu

The copytree method of shutil module

The copytree method of the shutil module copies a folder with all the files and folders that are in it. In the first parameter of the method, we specify the source path to the folder. In the second parameter, we specify the destination path. If the deletion is successful, the method returns the name of the new path of the copied folder.

Syntax

import shutil shutil.copytree(where do we copy from, where do we copy to)

Example

Let's recursively copy the folder dir:

import shutil print(shutil.copytree('dir', 'dir1'))

The result of the executed code:

dir1

See also

  • method move of module shutil,
    which recursively moves a file or directory
  • method rmtree of module shutil,
    which recursively deletes a folder
  • method makedirs of module os,
    which creates folders
  • method copy of module shutil,
    which copies a file while preserving the access mode
  • method copy2 of module shutil,
    which copies a file with metadata
  • method remove of module os,
    which deletes the file
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