Appending Date to a PDF file

Looking for some help..

I have a folder of PDF documents and I want to be able to add today’s date at the end of each PDF filename in bulk.

Any ideas much appreciated
Nick CollinsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Nick,

Bulk Rename Utility is a free utility that can do what you want:
http://www.bulkrenameutility.co.uk/Main_Intro.php

Even better is Flash Renamer, but it's not free (although it has a free trial):
http://www.rlvision.com/flashren/

Regards, Joe
0
Nick CollinsAuthor Commented:
I wanted to do it automatically by command line or script
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Three comments for you:

(1) Bulk Rename Utility has a command line feature:
http://www.bulkrenameutility.co.uk/Command.php

(2) Here's an AutoHotkey script that does it:

FormatTime,Today,,yyyy-MM-dd
Loop,Files,c:\temp\PDF files\*.pdf
{
  SplitPath,A_LoopFileFullPath,,Folder,FileExt,FileNameNoExt
  NewFileName:=Folder . "\" . FileNameNoExt . "_" . Today . "." . FileExt
  FileMove,%A_LoopFileFullPath%,%NewFileName%
}

Open in new window

I made the date format YYYY-MM-DD and I put an underscore between the current file name and today's date, but change those to whatever you want. Of course, change the Loop statement to have the folder where your PDF files are. If you're not familiar with AutoHotkey, this EE article will get you started:
AutoHotkey - Getting Started

(3) Keep the question open for a while and Bill Prew is likely to come around with a batch file (.bat) for it and oBdA with a PowerShell script for it.

Regards, Joe
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Bill PrewCommented:
What format do you want the date at the end of the PDF file names?   YYYYMMDD?

And this is for all PDF files in a single folder (so subfolders, etc)?


»bp
0
Nick CollinsAuthor Commented:
yyyymmddhhmmss

All the pdfs are located in one folder
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Do you want a separator, such as a hyphen or underscore, between yyyymmddhhmmss and the previous part of the file name?
0
Nick CollinsAuthor Commented:
Underscore thanks
0
Joe Winograd, Fellow&MVEDeveloperCommented:
Is hh in 12-hour or 24-hour format?
0
Nick CollinsAuthor Commented:
12 hour
0
Bill PrewCommented:
Here's how I would approach it, a relatively small BAT script.

@echo off
setlocal

REM Define folder to process
set BaseDir=C:\dir1\dir2

REM Get current date in YYYYMMDDhhmmss
set TimeStamp=
for /f "tokens=* skip=1" %%A in ('wmic os get LocalDateTime') do (
    if not defined TimeStamp set TimeStamp=%%A
)
set TimeStamp=%TimeStamp:~0,14%

REM Rename all ODF files adding time stamp
for %%F in ("%BaseDir%\*.pdf") do (
    ren "%%~F" "%%~nF_%TimeStamp%%%~xF"
)

Open in new window


»bp
1
Joe Winograd, Fellow&MVEDeveloperCommented:
Here's the modified AutoHotkey script that does everything you asked for:

FormatTime,Today,,yyyyMMddhhmmss
Loop,Files,c:\temp\PDF files\*.pdf
{
  SplitPath,A_LoopFileFullPath,,Folder,FileExt,FileNameNoExt
  NewFileName:=Folder . "\" . FileNameNoExt . "_" . Today . "." . FileExt
  FileMove,%A_LoopFileFullPath%,%NewFileName%
}

Open in new window

Tested here...works perfectly. For example, it turned the name of this PDF file:

test pdf file.pdf

into this:

test pdf file_20180417104915.pdf

It did it for all PDFs in the folder. Regards, Joe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewCommented:
Just saw your last answer, I would strongly advise using 24 rather than 12 hour format.  It opens the door to sortability and I think makes the time stamp easier to read as well.

Just curious, and since it sometimes yields better solutions, can you share why you are renaming the files in this manner?


»bp
1
Joe Winograd, Fellow&MVEDeveloperCommented:
Following up on Bill's excellent comment, if you do decide on 24-hour format, simply change the hh to HH in the AutoHotkey script, i.e., change the FormatTime line to:

FormatTime,Today,,yyyyMMddHHmmss

Regards, Joe

Update: Just tested Bill's script. As always with his batch files...works perfectly!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.