How do I copy files from Python?

Asked 1 years ago, Updated 1 years ago, 69 views

I want to know how to copy the file. I thought it would be in the os module, so I looked it up, but it's not here ㅜ<

python filesystems

2022-09-22 22:35

1 Answers

shutilUse the module

I'll tell you 2 ways.

src = '/dir1/filename'
dst = '/dir2'
copyfile(src, dst)

copyfile() is

import shutil
shutil.copy2('/dir/file.ext', '/new/dir/newname.ext')

#or
shutil.copy2('/dir/file.ext', '/new/dir')


2022-09-22 22:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.