Created
November 10, 2018 03:25
-
-
Save xax007/f70af3fe1a2e9f40214e0bbe5ae2e929 to your computer and use it in GitHub Desktop.
Python - Change the pdf file name from 'blahblah-abc.pdf' to 'Abc-blahblah.pdf'
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 os | |
def main(): | |
for root, dirs, files in os.walk(os.getcwd()): | |
for file in files: | |
filename, file_extension = os.path.splitext(file) | |
if file_extension.startswith('.pdf'): | |
# change pdf files filename from 'blahblah-abc' to 'Abc-blahblah' | |
new_filename = filename.split('-')[1].title() + '-' + filename.split('-')[0] | |
os.rename(file, new_filename+file_extenion) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment