Skip to content

Instantly share code, notes, and snippets.

@chulini
Created March 16, 2021 19:43
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 chulini/8ea218fecd437d38131fd250fe95f590 to your computer and use it in GitHub Desktop.
Save chulini/8ea218fecd437d38131fd250fe95f590 to your computer and use it in GitHub Desktop.
python script to rename pdf files from "dd-mm-yyyy Filename.pdf" to "yyyy-mm-dd Filename.pdf"
# to rename pdf files from "dd-mm-yyyy Filename.pdf" to "yyyy-mm-dd Filename.pdf"
import os
def main():
for count, fullfilename in enumerate(os.listdir(".")):
file_name, file_extension = os.path.splitext(fullfilename)
if file_extension == ".pdf":
date = fullfilename[0:10].split('-')
newFilename = date[2]+"-"+date[1]+"-"+date[0]+fullfilename[10:]
print fullfilename+" -> "+newFilename
os.rename(fullfilename, newFilename)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment