• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 39
  • Last Modified:

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
0
Nick Collins
Asked:
Nick Collins
  • 6
  • 4
  • 3
1 Solution
 
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now