This question already has an answer here:
- How to rename a file using Python 10 answers
- Rename multiple files in Python 2 answers
I'm trying to rename some files in a directory using Python.
Say I have a file called CHEESE_CHEESE_TYPE.***
and want to remove CHEESE_
so my resulting filename would be CHEESE_TYPE
I'm trying to use the os.path.split
but it's not working properly. I have also considered using string manipulations, but have not been successful with that either.
This works for me.
Use
os.rename(src, dst)
to rename or move a file or a directory.Here's a script based on your newest comment.