Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Copy Files

copy2 is the preferred function to copy files as it is more flexible (than copy) and also preserve file metadata (compared to copyfile).

copyfileobj

shutil.copy2 siliently overwrite the destination file if it already exists, which is consistent with the behavior of the cpcomamnd in Linux/Unix.

'abc'
testing

shutil.copytree

https://docs.python.org/3/library/shutil.html#shutil.copytree

shutil.copytree copies the content of the source directory to the destination directory.

1.txt
2.txt
'test2/'
1.txt  2.txt

Below is an example of copying ~/.ssh to another location /tmp/ssh but skipping sockets.