Skip to main content
martin_1000
Participant
October 25, 2017
Answered

Rename PDF files in specific date format

  • October 25, 2017
  • 3 replies
  • 3242 views

My goal is to change a lot of PDF file names (in windows).

Now the files are like: April, 1 2009 Wednesday.

I would like to change that to 2009_04_01_04042009. That is, in the format Year_Month_Day_DayMonthYear.

Does anyone know how to do this? That would be incredibly helpful!

This topic has been closed for replies.
Correct answer B i r n o u

Hello Martin, Sorry for have delayed on this one...

well, just create a txt file and name it as you like but using a .bat extension

then place it inside the foler where the file are named as you described above

copy paste the code below, and once saved, double clik on the bat file... the DOS will handle the magic

be aware to copy saved the old file, just in case of an unexpected error...

let me know if that fits your needs

have a pleasant day

birnou

@ECHO off  

SETLOCAL EnableDelayedExpansion

SET map[January]=01

SET map[February]=02

SET map[March]=03

SET map[April]=04

SET map[May]=05

SET map[June]=06

SET map[July]=07

SET map[August]=08

SET map[September]=09

SET map[October]=10

SET map[November]=11

SET map[December]=12

FOR %%a in (*.pdf) do (

  SET OLD_FILE_NAME=%%~na

  FOR /F "tokens=1,2,3 delims=,. " %%P in ("%%a") do  ( 

    SET M=!map[%%~nP]!

    SET D=000000%%~nQ

    SET Y=%%~nR

    SET NEW_FILE_NAME=!Y!_!M!_!D:~-2!_!D:~-2!!M!!Y!

    RENAME "!OLD_FILE_NAME!.pdf" "!NEW_FILE_NAME!.pdf"

  )

)

ECHO DONE

PAUSE

3 replies

B i r n o u
B i r n o uCorrect answer
Legend
October 29, 2017

Hello Martin, Sorry for have delayed on this one...

well, just create a txt file and name it as you like but using a .bat extension

then place it inside the foler where the file are named as you described above

copy paste the code below, and once saved, double clik on the bat file... the DOS will handle the magic

be aware to copy saved the old file, just in case of an unexpected error...

let me know if that fits your needs

have a pleasant day

birnou

@ECHO off  

SETLOCAL EnableDelayedExpansion

SET map[January]=01

SET map[February]=02

SET map[March]=03

SET map[April]=04

SET map[May]=05

SET map[June]=06

SET map[July]=07

SET map[August]=08

SET map[September]=09

SET map[October]=10

SET map[November]=11

SET map[December]=12

FOR %%a in (*.pdf) do (

  SET OLD_FILE_NAME=%%~na

  FOR /F "tokens=1,2,3 delims=,. " %%P in ("%%a") do  ( 

    SET M=!map[%%~nP]!

    SET D=000000%%~nQ

    SET Y=%%~nR

    SET NEW_FILE_NAME=!Y!_!M!_!D:~-2!_!D:~-2!!M!!Y!

    RENAME "!OLD_FILE_NAME!.pdf" "!NEW_FILE_NAME!.pdf"

  )

)

ECHO DONE

PAUSE

Bernd Alheit
Community Expert
Community Expert
October 25, 2017

In Adobe Acrobat you can't rename files. You can save copy of the PDF with a new name.

B i r n o u
Legend
October 26, 2017

yep, but martin will have to manually repeat hundreds time this operation, without avoiding the fact of calculating by head what should be the new name depending on the date algorythm...

that's why I supose that he looks for a batching process...

Bernd Alheit
Community Expert
Community Expert
October 26, 2017

I understand this, but Adobe Acrobat can't rename files.

B i r n o u
Legend
October 25, 2017

what's about a command prompt...

are the files already created... or will you run a batch process?

martin_1000
Participant
October 25, 2017

Right now, the files are like this (there are many more), so they are already created:

A command prompt could possibly work but I have very little experience in working with them. Nevertheless, the very limit number of variables (days, months, years) gives me the idea that it would not be too complex to construct such a code.

B i r n o u
Legend
October 25, 2017

are you in a hurry... I'm pretty busy right now, but , one of these days, I could write such a .bat file...