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.
Move and rename files with Python - Python Tutorial
From the course: Python: Working with Files
Move and rename files with Python
- [Instructor] Moving and renaming files are common operations in Python programs. For example, you may want to move current files into a separate directory to make space for new files. You also might want to rename a set of files to reference the date or year they were created in. When we move a file, we change its file path. Instead of home/desktop/example.png, we might move it to home/desktop/homework/example.png. In changing its path, we move the file to a new path. However, if we changed home/desktop/example.png to home/desktop/example1.png, we've renamed the file. Technically, we've moved it to this new file path, but in Python, we consider this operation renaming the file. We can rename a file using either the OS module or the pathlib module. For the OS module, we can use the rename method. The first input will be the current name of the file. In this case, we're going to rename monster01.png. The second input will be the…
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
-
-
-