Save as with {Filename}_date .pdf

Michael Katz
Michael Katz used Ask the Experts™
Good evening,

I have a report that will run 1 time a day...I need a process to run when a file is saved...then rename it to {FileName}_032117..It will need to run on Terminal Server with Server 2012 R2 Datacenter...
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If 032117 constitutes a date, I suggest you use format 170321, this way it is natively sortable.
Tahir QureshiSystem Analyst

you can use the following script

In my Config.js file (Location: C:\Program Files\adobe\Reader 9.0\Reader\Javascripts)

//DateTime function
function myDateString()
todayDate = new Date();
myYear = todayDate.getFullYear(); //return the four digit year
myMonth = todayDate.getMonth(); //return the month
myDate = todayDate.getDate(); //return the day of the month
myHour = todayDate.getHours(); //return the hours
myMin = todayDate.getMinutes(); //return the minutes
mySec = todayDate.getSeconds(); //return the seconds

myNewDate = myYear.toString() + myMonth.toString() + myDate.toString() + "_" + myHour + myMin + mySec;

return myNewDate;

// SaveAs Function
function saveDoc()
var myDoc = app.newDoc();
var myPath = app.getPath("user", "documents") + "/WebRequestFiles/" + myDateString() + ".pdf"

In MySaveAsForm.pdf (click event of "regular" button):

// SaveAs Function
var SaveRequest = app.trustedFunction(saveDoc());

Open in new window

You can use something as follows within a batch file:

@echo off
set newfile=%1%date:~6,4%%date:~3,2%%date:~0,2%
echo %1 %newfile%

Open in new window

Few things to note. First type %date% at dos prompt and see the format of date printed. Yours might be different than mine. You will need to adjust the string off-sets depending on the date you get. Or simply paste the date you get here.

You will need to change the last line and replace echo with rename.

Moving the filename extension towards the end is not been taken care of.

The logic is dependent on regional settings of the computer.

If you save above in a renfile.bat (for example) you will be able to use it by passing a parameter to batch file, as in renfile yourfilenamehere.txt
Lead Technical Consultant
I assume you want the output file to be saved using the date format and  if you are using powershell use this after the get command.

Get-Mailbox -ResultSize Unlimited | Export-Csv "C:\LJ_$((Get-Date).ToString('dd-MMM-yyyy')).csv" –NoTypeInformation

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial