How to create a date folder for yesterday?

I normally use the command

CreateFolder Name "{date|dd-MMM-yy}" READAUTO

to create date folders, but quite often, due to post production taking quite some time, need something like CreateFolder Name "{date|dd-MMM-yy}"-1 READAUTO or similar. Is this possible anyway, without using scripts?

1 Like

No you'd need a simple script.

Near the top, change this line:

	d.setDate(d.getDate() + 1); // Move date part to tomorrow.

to use - 1 instead of + 1 if you want yesterday instead of tomorrow. I think the rest should be fine as-is, except for changing the date format to what you want.

That's very interesting. It also works after a few changes, which means, i didn't mess it up completely. :slight_smile:

<?xml version="1.0"?>

** Tomorrow Folder**
** #makedir**
** **
** @script JScript**
** function OnClick(clickData)**
** {**
** var d = new Date(); // Today**
** d.setDate(d.getDate() - 1); // Move date part to tomorrow.**
** **
** var dd = d.getDate();**
** var MMM = d.getMonth() + 1; // Jan=0,Feb=1,etc.**
** var yyyy = d.getFullYear();**
** var day = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][ d.getDay() ];**
** **
** if (dd < 10) dd = "0" + dd; // Pad to 2 digits**
** if (MMM < 10) mm = "0" + MMM; // Pad to 2 digits**
** **
** var ds = dd + "-" + MMM + "-" + yyyy + " "**
** **
** clickData.func.command.RunCommand("CreateFolder READAUTO=no NAME=&quot;" + ds + "&quot;");**
** }**
** **

Looks like JScript doesn't understand "MMM", so i'm just almost there

17-7-2018

i have tried to get 17-Jul-2018 instead. But so far it works! :smiley:

Thanks!

Interestingly, in this case VBScript seems to be a bit easier (still embarrassingly cumbersome if you are used to Excel).

Option Explicit
Function OnClick(ByRef clickData)
    Dim myDate, myFolder, myCommand
    myDate = Date-1
    myFolder = Right("0" & DatePart("d", myDate),2) & "-" & MonthName(DatePart("m", myDate),true) & "-" & DatePart("yyyy", myDate)
    myCommand = "CreateFolder READAUTO=no NAME=" & CHR(34) & myFolder & CHR(34)
    clickData.func.command.RunCommand myCommand
End Function

Not sure why I didn't do this originally, but here's a better way for both languages:

Function OnClick(ByRef clickData)
	Set d = DOpus.Create.Date()
	d.Sub 1, "d"
	ds = d.Format("D#dd-MMM-yy")

	clickData.func.command.RunCommand "CreateFolder READAUTO=no NAME=""" & ds & """"
End Function
function OnClick(clickData)
{
	var d = DOpus.Create.Date();
	d.Sub(1,"d");
	var ds = d.Format("D#dd-MMM-yy");

	clickData.func.command.RunCommand("CreateFolder READAUTO=no NAME=\"" + ds + "\"");
}

(I've updated the other thread as well.)

1 Like

Cool, works! Thanks guys!

Excellent! Wasn't aware that Opus' date formatting is superior to VBS' and JS' :+1: