Skip to main content
Inspiring
April 23, 2014
Answered

adding date to filename

  • April 23, 2014
  • 2 replies
  • 1296 views

I'm trying a to automatically add the date to an items name in the render queue.

I have the following.

var x = app.project.renderQueue.item(1).outputModule(1);  

alert (x.file.name);

This returns the name of the file that will be output but I'm unable to change this value. The scripting guide says this attribute is read/write but I can't figure out how to alter it.

Thanks.

This topic has been closed for replies.
Correct answer David Torno

var d = new Date();

var separator = "/";

var dateSuffix = (d.getMonth()+1).toString() + separator + d.getDate().toString() + separator + d.getFullYear().toString().substring(4, 2);

alert(dateSuffix);     //Returns 5/12/14

2 replies

David TornoCorrect answer
Legend
May 13, 2014

var d = new Date();

var separator = "/";

var dateSuffix = (d.getMonth()+1).toString() + separator + d.getDate().toString() + separator + d.getFullYear().toString().substring(4, 2);

alert(dateSuffix);     //Returns 5/12/14

brendanTAuthor
Inspiring
May 13, 2014

Thanks gents. Big help. Actually David you solved my major problem on this issue with the provideo coalition tutorials.

Here is the script I ultimately wound up writing. Le me know if you think I should have done something different.

var d = new Date ();
var nnum = d.getDate();
var mnum = d.getMonth() + 1;
var ynum = d.getFullYear();
var n = nnum.toString();
var m = mnum.toString();
var y = ynum.toString();
if (mnum <= 9) {
m = "0" + m
}
if (nnum <= 9) {
n = "0" + n
}
// y = y.slice(2);
//change your date format here
var writeDate = m+n+y;


var proj = app.project;
var myRQ = proj.renderQueue;
var numOM, oldName;
var path = "";
var fileExt =""

for(var i = 1; i <= myRQ.numItems; i++) {
if(app.project.renderQueue.item(i).status == 2615){
oldName = myRQ.item(i).outputModule(1).file.name;
fileExt = oldName.slice(oldName.length - 4)
oldName = oldName.substring(0, oldName.length - 4);
newName = oldName + "_" + writeDate;
path = myRQ.item(i).outputModule(1).file.path;
myRQ.item(i).outputModule(1).file = new File(path + "/" + newName + fileExt);
numOM = myRQ.item(i).outputModules.length;
if(numOM > 1){
for(var o = 2; o <= numOM; o++){
oldName = myRQ.item(i).outputModule(o).file.name;
fileExt = oldName.slice(oldName.length - 4)
oldName = oldName.substring(0, oldName.length - 4);
newName = oldName + "_" + writeDate;
path = myRQ.item(i).outputModule(o).file.path;
myRQ.item(i).outputModule(o).file = new File(path + "/" + newName + fileExt);
}
}
}
}

Legend
April 23, 2014

Have you tried setting the .file property of the RenderItem to a new File() object that uses the filename you want?

var defaultName = renderItem.outputModule(1).file.name,

newFilename = defaultName + “_” + Date(); //probably need some get the date back in a more elegant way

renderItem.outputModule(1).file = File(newFileName);

—Arie