From the course: Python: Working with Files

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Copy with Python

Copy with Python

- [Instructor] The shutil module also provides ways to copy files. To copy a file from one folder to another, we can use shutil.copy. The first input is the file we want to copy. In this case, it'll be monster01.png. The second input is the folder we want to copy it to. In this case, we'll put it in the images/png folder. It's important to note that this function only copies a files' contents and permissions. Other metadata like file creation time and modification times are erased. To keep all the metadata when copying a file, we can use the copy to function. For this example, we'll copy monster02, and we'll put it in the same place, images/png. Let's call these in our program. And we'll execute it. If we open up our images/png folder, we can see monster01 and monster02 have been copied. If we look at the metadata for each png file, we can see some differences. Monster01 was modified today whereas monster02 was…

Contents