Michael Katz
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...
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...
If 032117 constitutes a date, I suggest you use format 170321, this way it is natively sortable.
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());
You can use something as follows within a batch file:
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
@echo off
set newfile=%1%date:~6,4%%date:~3,2%%date:~0,2%
echo %1 %newfile%
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.