GP SoftwareTwitter
Opus FAQsManualCommandsObjects

How to create folder name with tomorrow(next date)?

Hello everybody,

I know to making a new dated folder is CreateFolder NAME="{date|yyyy-MM-dd ddd}"
(ex: Today Folder name=2017-09-17 Sun)

I want to know
How can I make new next(tomorrow) dated folder?
(ex: Tomorrow Folder name=2017-09-18 Mon)

Thank you!

Finally after an hour of research I came up with a very simple solution. I didn't know it would be so hard to do. Maybe more experienced minds have a simpler answer

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" separate="yes" textcol="none">
	<label>Create Tomorrow Folder</label>
	<function type="script">
		<instruction>@script VBScript</instruction>
		<instruction>Option Explicit</instruction>
		<instruction>Function OnClick(ByRef clickData)</instruction>
		<instruction>	Dim d</instruction>
		<instruction>	d = WeekDayName(WeekDay(now+1),True)</instruction>
		<instruction>	clickData.func.command.RunCommand(&quot;CreateFolder NAME=&quot;&quot;&quot; &amp; date + 1 &amp; &quot; &quot; &amp; d &amp; &quot;&quot;&quot;&quot;)</instruction>
		<instruction>End Function</instruction>

This will create a folder with tomorrow's date in the current lister, example 2017-09-29 Fri

I make a button and click it. Shows like this. Each folder makes subfolder.

How can I use this script?


That's strange,
are you saying it creates subfolders, rather than a single one?

Does it have anything to do with your new folder creation settings? (i.e. new folder seperated by dash?)
it works well here

You can try changing the separator to something else in the button.


does your button code look like this

What is your regional settings? Is it set to the US?

Oh I figured it out now! If you add Dopus.Output(date+1) I'm sure you'll see 2017/10/05 , so the slashes are getting converted into subfolders, you need to change the formats on your system or manually change the slashes to dashes.
You can try to add this code replace(date+1,"\","-") or replace(date+1,"/","-") instead of date+1. I haven't tested it, try to experiment with it.

Or you could format the date which is cumbersome in vb

The script above outputs appends the date to the command string without specifying a format.

With VBScript, that probably means it will use the system date format. If there are / characters in that format, then they'll be in the command line the script generates, and the script will create sub-directories.

This thread has an example of how to get tomorrow's date and format it in a specific way from a script. It's a Rename script, using JScript instead of VBScript, but the general idea is the same:

replace(date+1,"","-") or replace(date+1,"/","-") instead of date+1 doesn't work.

What about Leo's solution, that seems like it should work as well, and it contains more formatting options.
Do you have experience with scripting?

This should do what you want:

The script, for reference:

function OnClick(clickData)
	var d = new Date(); // Today
	d.setDate(d.getDate() + 1); // Move date part to tomorrow.

	var dd = d.getDate();
	var mm = 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 (mm < 10) mm = "0" + mm; // Pad to 2 digits

	var ds = yyyy + "-" + mm + "-" + dd + " " + day;

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

Edit: Here's a nicer way of doing the same thing:

function OnClick(clickData)
	var d = DOpus.Create.Date();
	var ds = d.Format("D#YYYY-MM-dd ddd");

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

Leo''s Tomorrow Folder.dcf works perfect.
Thank you!