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 - Python Tutorial
From the course: Python: Working with Files
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Write data to a file in Python3m 36s
-
(Locked)
Move and rename files with Python3m 23s
-
(Locked)
Copy with Python2m 29s
-
(Locked)
Delete files with Python3m 17s
-
(Locked)
Save tabular data with csv module4m 5s
-
(Locked)
Write data to a JSON file in Python1m 48s
-
(Locked)
Solution: Rename and Reorganize Photo Files2m 24s
-
(Locked)
</> Solution: Parse JSON file with Python1m 19s
-
-
-