Q3
How do you copy an entire directory recursively in Python?
💬Answer
Use shutil.copytree(src, dst). It copies the entire directory tree from src to a new directory named dst (which must not exist beforehand unless dirs_exist_ok=True is set).
import shutil
shutil.copytree("/var/log/nginx", "/backup/nginx_logs", dirs_exist_ok=True)
Related Python Questions
View All PythonQuestions →
Created by
Apurv Gujjar
DevOps & Cloud Engineer
Specialized in:DevOpsAWSGCPKubernetesTerraformDocker
View Portfolio