Skip to content

Instantly share code, notes, and snippets.

@xax007
Created November 10, 2018 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xax007/f70af3fe1a2e9f40214e0bbe5ae2e929 to your computer and use it in GitHub Desktop.
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'
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