Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Copy ไฟล์ใน Python

ใช้ shutil.copy(source, destination) จากโมดูล shutil คัดลอกไฟล์และโฟลเดอร์ได้

ตัวอย่าง

>>> import shutil
>>> shutil.copy('original.txt', 'duplicate.txt')
'/home/username/duplicate.txt'
>>> shutil.copy('original.txt', 'my_folder/duplicate.txt')
'/home/username/my_folder/duplicate.txt'