The part I'm trying to simplify is step 1 of a 3 step workflow. The "R-" and S-" are used in step 2 (not described.)
Also, I don't always know where the start folder is, so i want the command to locate it for me. For example, I may not know if Honda is under c:\cars\ or c:\trucks.
So a command would help me go right to it and set me up for review.
The ideal result would be i type a command like:
/Honda
// https://resource.dopus.com/t/is-it-possible-to-enter-a-command-and-have-2-panes-update/40657
function OnClick(clickData) {
var cmd = clickData.func.command;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
cmd.deselect = false;
var st = dlg.GetString('Folder to open:', st);
if (typeof st != 'string') return;
var leftStartfolder = 'C:\\Unreviewed';
var rightStartfolder = 'C:\\Reviewed';
var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
}
folderEnum.Close();
var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
}
folderEnum.Close();
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" hotkey="/" textcol="none">
<label>40657</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/is-it-possible-to-enter-a-command-and-have-2-panes-update/40657</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var dlg = clickData.func.Dlg();</instruction>
<instruction> var fsu = DOpus.FSUtil();</instruction>
<instruction> cmd.deselect = false;</instruction>
<instruction />
<instruction> var st = dlg.GetString('Folder to open:', st);</instruction>
<instruction> if (typeof st != 'string') return;</instruction>
<instruction />
<instruction> var leftStartfolder = 'C:\\Unreviewed';</instruction>
<instruction> var rightStartfolder = 'C:\\Reviewed';</instruction>
<instruction />
<instruction> var folderEnum = fsu.ReadDir(leftStartfolder, 'r');</instruction>
<instruction> while (!folderEnum.complete) {</instruction>
<instruction> var item = folderEnum.Next();</instruction>
<instruction> if (!item.is_dir) continue;</instruction>
<instruction> if (String(item.realpath).indexOf(st) < 0) continue;</instruction>
<instruction> cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');</instruction>
<instruction> }</instruction>
<instruction> folderEnum.Close();</instruction>
<instruction />
<instruction> var folderEnum = fsu.ReadDir(rightStartfolder, 'r');</instruction>
<instruction> while (!folderEnum.complete) {</instruction>
<instruction> var item = folderEnum.Next();</instruction>
<instruction> if (!item.is_dir) continue;</instruction>
<instruction> if (String(item.realpath).indexOf(st) < 0) continue;</instruction>
<instruction> cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');</instruction>
<instruction> }</instruction>
<instruction> folderEnum.Close();</instruction>
<instruction>}</instruction>
</function>
</button>
I got that to work if i type in "C:\Unreviewed\Cars\Toyota"
The problem is that i may not know where it is and that's a lot of typing, especially since in real life this is on a network share.
I just want to be able to type in "honda" and have it set the panes.
I'm able to programmatically generate a long list that has hundreds of pairs formatted for the script.
IT WOULD BE GREAT IF I COULD:
Hit a button
it prompts me for a keyword
a loooong series of IF statements gets checked and if there is a hit it updates 2 variables for the top and bottom pane location
It sets the panes if the variables are not null at the very end.
Would it be possible to get me going with something like this? Once I see the beginnings of a script that can take the parameter, establish the 2 variables and then at the end update the panes I can probably take it from there.
I tried to take your script and modify it like i outlined in the 1,2,3,4 just above.
I pasted this as a javascript button but it won't work. I think it might be very close to what I'm looking for.
I only have a line for "Honda" in there but i can repeat it when i get everything else to work.
Could you give a bit of guidance? I'm a sql programmer. I don't know Javascript.
function OnClick(clickData) {
var cmd = clickData.func.command;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
cmd.deselect = false;
// Get the collection name
var st = dlg.GetString('Collection:', st);
if (typeof st != 'string') {return};
// set the collection name based on a keyword
if (st = 'honda') { var leftStartfolder = 'C:\Unreviewed\Trucks\Honda'; var rightStartfolder = 'C:\Reviewed\S-Trucks\Honda'; }
// If i didn't get a hit abort.
if (typeof leftStartfolder != 'string') {return};
if (typeof rightStartfolder != 'string') {return};
// set the top pane
var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
}
folderEnum.Close();
// set the bottom pane
var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
}
folderEnum.Close();
I think we're super close. But for some reason it's prefixing the windows system directory in front of the variable:
If i type honda it tries to go to C:\Windows\System32\ReviewedS-TrucksHonda and c:\Windows\System32\UnreviewedTrucksHonda
I pasted the directories into the script to make sure they were exact.
Why would it prefix the windows directory?
function OnClick(clickData) {
var cmd = clickData.func.command;
var dlg = clickData.func.Dlg();
cmd.deselect = false;
var st = dlg.GetString('Collection Name:', st);
if (typeof st != 'string') return;
if (false);
else if (st == 'honda') cmd.RunCommand('GO PATH="C:\Unreviewed\Trucks\Honda" DUALPATH="C:\Reviewed\S-Trucks\Honda\"');
else if (st == 'toyota') cmd.RunCommand('GO PATH="C:\Unreviewed\Cars\Toyota" DUALPATH="C:\Reviewed\R-Cars\Toyota"');
}
Hi LXP,
Sometimes these folders may not exist so to prevent an error, it should only change to them if they are there. Your early code had this check but i can't get it to work.
I'm setting the variables with the else if's then just opening the tabs at the bottom if they exist. This was setup combining the different versions you provided. If you could look at the tab openings and give me an idea why the check isn't working that would be great.
Here's what I have:
function OnClick(clickData) {
var cmd = clickData.func.command;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
cmd.deselect = false;
// Fetch collection name
var st = dlg.GetString('Collection Name:', st);
if (typeof st != 'string') return;
// set the top/bottom pane variables based on a keyword entered
if (false);
else if (st == 'honda') { var leftStartfolder = 'C:\\Unreviewed\\Trucks\\Honda'; var rightStartfolder = 'C:\\Reviewed\\S-Trucks\\Honda'; }
else if (st == 'toyota') { var leftStartfolder = 'C:\\Unreviewed\\Cars\\Toyota'; var rightStartfolder = 'C:\\Reviewed\\R-Cars\\Toyota'; }
// set the top pane if the directory exists
var folderEnum = fsu.ReadDir(leftStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINLEFT');
}
folderEnum.Close();
// set the bottom pane if the directory exists.
var folderEnum = fsu.ReadDir(rightStartfolder, 'r');
while (!folderEnum.complete) {
var item = folderEnum.Next();
if (!item.is_dir) continue;
if (String(item.realpath).indexOf(st) < 0) continue;
cmd.RunCommand('GO PATH="' + item + '" NEWTAB OPENINRIGHT');
}
folderEnum.Close();
}
There are two approaches for the script. Either search for the folder in the directory structure or look up the folder from a table. A search can be slower and might return unwanted results. A look-up table is very precise, but needs a bit of maintenance, as you just found out.
You need to decide which solution works best for you.
Sorry my bad, I'm not being clear enough. This is a pretty extensive workflow I'm trying to introduce this to.
Sometimes, these folders are not there but, they belong there. The script will absolutely know where they belong based on a database i have. However, If they haven't been created (yet) I need to check for that to prevent an error.
So that's why I'm looking to simply check the existence of the directory before attempting to open it. Ideally, I'd like to create it if it doesn't exist. At the least I need to check it's existence and prevent it from getting an error.
How can I identify the existence of a folder before attempting to open/create it in a pane?
I got it! Now it creates a directory if it doesn't exist too!
I have over 800 else ifs in my final version and it's super quick!
This is going to do so much "looking stuff up" for me.
Thanks so much lxp & Leo! Directory Opus rules!
Here's my final version if anyone ever needs it. All someone needs to do is populate the else if's with rows of their choosing and pairs will appear when they match what's typed in the dialog:
function OnClick(clickData) {
var cmd = clickData.func.command;
var dlg = clickData.func.Dlg();
var fsu = DOpus.FSUtil();
cmd.deselect = false;
DOpus.ClearOutput();
// Fetch collection name
var st = dlg.GetString('Collection Name:', st);
if (typeof st != 'string') return;
// set the top/bottom pane variables based on a keyword entered
if (false);
else if (st == 'honda') { var leftStartfolder = 'C:\\Unreviewed\\Trucks\\Honda'; var rightStartfolder = 'C:\\Reviewed\\S-Trucks\\Honda'; }
else if (st == 'toyota') { var leftStartfolder = 'C:\\Unreviewed\\Cars\\Toyota'; var rightStartfolder = 'C:\\Reviewed\\R-Cars\\Toyota'; }
DOpus.Output('collection name = '+ st);
DOpus.Output('leftStartfolder = '+ leftStartfolder);
DOpus.Output('rightStartfolder = '+ rightStartfolder);
if (typeof leftStartfolder == 'undefined') { DOpus.Output('Aborting: Top Doesnt Exist'); return;}
if (typeof rightStartfolder == 'undefined') { DOpus.Output('Aborting: bottom Doesnt Exist'); return;}
// Find out if these directories exists
var leftexists = fsu.Exists(leftStartfolder);
if (leftexists == false) DOpus.Output('Top Doesnt Exist');
if (leftexists == true) DOpus.Output('Top Exists');
var rightexists = fsu.Exists(rightStartfolder);
if (rightexists == false) DOpus.Output('Bottom Doesnt Exist');
if (rightexists == true) DOpus.Output('Bottom Exists');
// set the top pane
if (leftexists == false) {
cmd.SetSourceTab(cmd.sourcetab);
cmd.RunCommand('CreateFolder NAME="' + leftStartfolder + '" READAUTO');
leftexists = fsu.Exists(leftStartfolder);
}
if (leftexists == true) cmd.RunCommand('GO PATH="' + leftStartfolder + '" NEWTAB OPENINLEFT');
// set the Bottom pane if the directory exists
if (rightexists == false) {
cmd.SetSourceTab(cmd.desttab);
cmd.RunCommand('CreateFolder NAME="' + rightStartfolder + '" READAUTO');
rightexists = fsu.Exists(rightStartfolder);
}
if (rightexists == true) cmd.RunCommand('GO PATH="' + rightStartfolder + '" NEWTAB OPENINRIGHT');
}