Avatar of Michael Katz
Michael Katz
Flag for United States of America asked on

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

Avatar of undefined
Last Comment
Ganesh Anand

8/22/2022 - Mon
Nitin Sontakke

If 032117 constitutes a date, I suggest you use format 170321, this way it is natively sortable.
Tahir Qureshi

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()
{
app.beginPriv();
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;
app.endPriv();
}


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


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

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

Open in new window

Nitin Sontakke

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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Ganesh Anand

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.