Save as with {Filename}_date .pdf

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...
Michael KatzAsked:
Who is Participating?
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.

Nitin SontakkeDeveloperCommented:
If 032117 constitutes a date, I suggest you use format 170321, this way it is natively sortable.
Tahir QureshiSystem AnalystCommented:
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

Nitin SontakkeDeveloperCommented:
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
Ganesh Kumar ASr Infrastructure SpecialistCommented:
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

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
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
Windows Server 2012

From novice to tech pro — start learning today.