简体   繁体   中英

How do I copy a folder and its contents (files/subdirectories) in Python with platform independent implementation

I need a function in python that lets me specify the source and destination paths for a folder and copies the source folder recursively into the destination folder. The implementation I am looking for needs to be platform independent

You could use shutil.copytree :

shutil.copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False)

Recursively copy an entire directory tree rooted at src, returning the destination directory. The destination directory, named by dst, must not already exist; it will be created as well as missing parent directories. Permissions and times of directories are copied with copystat(), individual files are copied using shutil.copy2().


import shutil
shutil.copytree(src, dst)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM