We help IT Professionals succeed at work.

Save as with {Filename}_date .pdf

Michael Katz
Michael Katz asked
on
43 Views
Last Modified: 2018-02-22
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...
Comment
Watch Question

Nitin SontakkeDeveloper
CERTIFIED EXPERT

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

Commented:
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 SontakkeDeveloper
CERTIFIED EXPERT

Commented:
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
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION