Last active
October 12, 2021 15:32
-
-
Save samimisami/bebaa110bd89da6518e1cd2362e1a1ca to your computer and use it in GitHub Desktop.
File Name Changer in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
import shutil | |
def rename_files(): | |
path_data = pathlib.Path.cwd() / "z_ProjectFiles" | |
path_output = pathlib.Path.cwd() / "z_ProjectFiles" / "Renamed Files" | |
path_output.mkdir(parents=True, exist_ok=True) | |
for file in path_data.iterdir(): | |
if file != path_output: | |
print(file) | |
shutil.copy(file, path_output) | |
for file in path_output.iterdir(): | |
name_of_the_file = file.name | |
name_without_the_extension = name_of_the_file.replace('.txt', '') | |
new_file_name = name_without_the_extension + "_desktop" + file.suffix | |
file.rename(path_output / new_file_name) | |
if __name__ == '__main__': | |
rename_files() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment