Select folders which (sub)folder(s) contains certain file?

Try to click the button, while you keep the left "ALT" key pressed down, then you should see a line like I described.. o)

You try to edit the "raw" button code in xml, this is not nessecary and makes it much harder to not screw the code up. Xml-files are very picky.. o)

Strange.... When I hold the left "ALT" key down (the one left to the space bar) and I press the button the code is executed the normal way. The ALT key doesn't do anything.

Preferences / Toolbars / Options / Alt-Click to edit Toolbar buttons needs to be turned on for that to work.

Thanks Leo!

Please excuse being so used to my configuration, thinking it is default for everyone!.. o)

Thank you for your effort and your patience with me.
The button serves well for what Leo had initially promised :slight_smile:

Leo, you may thank tbone because of him I'm willing to buy it. I would feel ashamed if I did not after all of his help :smiley:
I'll hope he will help me in the future also :laughing:

Is there a discount that I can find somewhere? Leo? :wink:

Oh thanks, really, but all I know is' because of Leo and the guys doing excellent help and support here, so kudos to Leo and the crew, not nessecarily me.. o)
I hope you'll have some more greater moments with DO und us, cu around. o)

Can wildcards also be used in this line (example: *5.iso)?

var extension = '.iso';[

Is it only possible to search for an extension? Or is there a possibility to work with a part of the name?
For instance: If I want to search for DVD5 (part of "Cassadaga_DVD5.iso"), and select these folders.

Here you go.. o)


Now featuring:

  • progress dialog
  • search dialog
    • search only in extension
    • search only in stem
    • search full filename (if extension/stem checkboxes enabled)
    • optionally exclude folder (must be entered in the button code, as there is no way to have 2 text fields right now)
    • input validation.. o)
  • previously used search parameters will be preserved per tab
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Folder Selector</label>
	<tip>Folder Selector</tip>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script jscript</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>// Simple dialog based search to select folders.</instruction>
		<instruction>// Folders will be selected if they contain matching files and at the same</instruction>
		<instruction>// time do not contain a subfolder (optional).</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>var defaultSearch = new SearchParams(</instruction>
		<instruction>	/*search string*/	&apos;iso&apos;,</instruction>
		<instruction>	/*search extension*/	true,</instruction>
		<instruction>	/*search stem*/		false,</instruction>
		<instruction>	/*subfolder name*/	&apos;video_ts&apos;,</instruction>
		<instruction>	/*exclude subfolder*/	true</instruction>
		<instruction>);</instruction>
		<instruction />
		<instruction>var lastSearch = null;</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function OnClick(data){</instruction>
		<instruction>	DOpus.ClearOutput();</instruction>
		<instruction>	data.func.command.ClearFiles();</instruction>
		<instruction />
		<instruction>	//get enumerator and count of selected folders or complete list of folders</instruction>
		<instruction>	var folders = GetFolders(data);</instruction>
		<instruction />
		<instruction>	//get a combination of default, last used and current dialog search params</instruction>
		<instruction>	var params = GetSearchParams(data); if (!params) return; //dialog cancelled</instruction>
		<instruction />
		<instruction>	//save current search params</instruction>
		<instruction>	SaveSearchParams(data, params);</instruction>
		<instruction />
		<instruction>	//init, open and return progress dialog</instruction>
		<instruction>	var progress = OpenProgressDialog( data, &quot;Folder Selector..&quot;, folders.count);</instruction>
		<instruction />
		<instruction>	var searchMode = params.GetSearchMode();</instruction>
		<instruction>	while (!folders.enumerator.atEnd() ) {</instruction>
		<instruction>		var folder = folders.enumerator.item(); folders.enumerator.moveNext();</instruction>
		<instruction>		dout(&quot;Folder [&quot;+folder.name+&quot;]..&quot;);</instruction>
		<instruction>		progress.SetName(folder.name);</instruction>
		<instruction>		//if subfolder to exclude is given, search subfolders before looking for matching files</instruction>
		<instruction>		if (params.excludeFolder &amp;&amp; defaultSearch.excludeFolderName!=&quot;&quot; &amp;&amp; SubFolderExists( folder.path+&quot;\\&quot;+folder.name, defaultSearch.excludeFolderName)){</instruction>
		<instruction>			dout(&quot;    Contains subfolder [&quot;+defaultSearch.excludeFolderName+&quot;], skipping folder.&quot;);</instruction>
		<instruction>			progress.StepFiles(1);</instruction>
		<instruction>			continue;</instruction>
		<instruction>		}</instruction>
		<instruction>		if (exists = FileExists( folder.path+&quot;\\&quot;+folder.name, params.searchMe, searchMode)){</instruction>
		<instruction>			dout(&quot;    Contains at least one matching file.&quot;);</instruction>
		<instruction>			data.func.command.AddFile(folder);</instruction>
		<instruction>		}</instruction>
		<instruction>		progress.StepFiles(1);</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>	data.func.command.RunCommand(&quot;Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE&quot;);</instruction>
		<instruction>	progress.Hide();</instruction>
		<instruction>	DOMsgBox(&quot;ISO-FolderSelector&quot;,&quot;Found &quot;+data.func.command.files.count+&quot; folder(s) matching your search.&quot;,&quot;Ok&quot;);</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function ReadFolder( path, recurse, exception){</instruction>
		<instruction>	if (recurse == undefined) recurse=false;</instruction>
		<instruction>	if (exception == undefined) exception=true;</instruction>
		<instruction>	var fEnum = DOpus.FSUtil.ReadDir( path, true);</instruction>
		<instruction>	if (fEnum.error!=0){</instruction>
		<instruction>		var error = &quot;ReadFolder(): Error reading folder [&quot;+name+&quot;], code [&quot;+fEnum.error+&quot;].&quot;;</instruction>
		<instruction>		if (exception) throw error;</instruction>
		<instruction>		dout(error);</instruction>
		<instruction>	}</instruction>
		<instruction>	return fEnum;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function SubFolderExists( folderPath, subFolderName){</instruction>
		<instruction>	subFolderName = subFolderName.toLowerCase();</instruction>
		<instruction>	var fEnum = ReadFolder( folderPath, true, true);</instruction>
		<instruction>	while (!fEnum.complete &amp;&amp; (fItem = fEnum.Next()))</instruction>
		<instruction>		if (fItem.is_dir &amp;&amp; (fItem.name.toLowerCase() == subFolderName))</instruction>
		<instruction>			return true;</instruction>
		<instruction>	return false;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function FileExists( folderPath, searchMe, searchMode){</instruction>
		<instruction>	if (searchMode == undefined) searchMode=&apos;full&apos;;</instruction>
		<instruction>	searchMe = searchMe.toLowerCase();</instruction>
		<instruction>	if (searchMode==&apos;ext&apos;) searchMe=searchMe.replace(&apos;\.&apos;,&apos;&apos;);</instruction>
		<instruction>	var fEnum = ReadFolder( folderPath, true, true);</instruction>
		<instruction>	while (!fEnum.complete &amp;&amp; (fItem = fEnum.Next())){</instruction>
		<instruction>		if (fItem.is_dir) continue;</instruction>
		<instruction>		switch (searchMode){</instruction>
		<instruction>			case &apos;ext&apos;:</instruction>
		<instruction>				if (fItem.ext.toLowerCase()==&quot;.&quot;+searchMe)</instruction>
		<instruction>					return true;</instruction>
		<instruction>			break;</instruction>
		<instruction>			case &apos;stem&apos;:</instruction>
		<instruction>				if (fItem.name_stem.toLowerCase().indexOf(searchMe)!=-1)</instruction>
		<instruction>					return true;</instruction>
		<instruction>			break;</instruction>
		<instruction>			case &apos;full&apos;:</instruction>
		<instruction>			default:</instruction>
		<instruction>				if (fItem.name.toLowerCase().indexOf(searchMe)!=-1)</instruction>
		<instruction>					return true;</instruction>
		<instruction>			break;</instruction>
		<instruction>		}</instruction>
		<instruction>	}</instruction>
		<instruction>	return false;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function GetFolders(data){</instruction>
		<instruction>	if (data.func.sourcetab.selected_dirs.count)</instruction>
		<instruction>		var dirs = data.func.sourcetab.selected_dirs;</instruction>
		<instruction>	else</instruction>
		<instruction>		var dirs = data.func.sourcetab.dirs;</instruction>
		<instruction>	return { enumerator:new Enumerator(dirs), count:dirs.count};</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function DoDialog( params){</instruction>
		<instruction>	var dlg = DOpus.Dlg</instruction>
		<instruction>	dlg.window = DOpus.Listers(0);</instruction>
		<instruction>	dlg.message = &quot;Please enter string/extension to search for:\n &quot;;</instruction>
		<instruction>	dlg.title = &quot;Folder Selector..&quot;;</instruction>
		<instruction>	dlg.buttons = &quot;OK|Cancel&quot;;</instruction>
		<instruction>	dlg.icon = &quot;question&quot;;</instruction>
		<instruction />
		<instruction>	dlg.max = 128; //enable text field</instruction>
		<instruction>	dlg[&apos;default&apos;] = params.searchMe;</instruction>
		<instruction />
		<instruction>	dlg.options(0).label = &quot;search extension&quot;;</instruction>
		<instruction>	dlg.options(0).state = params.searchExtension;</instruction>
		<instruction />
		<instruction>	dlg.options(1).label = &quot;search stem&quot;;</instruction>
		<instruction>	dlg.options(1).state = params.searchStem;</instruction>
		<instruction />
		<instruction>	if (defaultSearch.excludeFolderName!=&quot;&quot;){</instruction>
		<instruction>		dlg.options(2).label = &quot;may not contain folder (&quot;+defaultSearch.excludeFolderName+&quot;)&quot;;</instruction>
		<instruction>		dlg.options(2).state = params.excludeFolder;</instruction>
		<instruction>	}</instruction>
		<instruction>	return dlg;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function OpenProgressDialog( data, title, numFiles){</instruction>
		<instruction>	var progress = data.func.command.progress;</instruction>
		<instruction>	progress.delay = false;</instruction>
		<instruction>	progress.abort = true;</instruction>
		<instruction>	progress.Init(data.func.sourcetab, title);</instruction>
		<instruction>	progress.AddFiles(numFiles);</instruction>
		<instruction>	progress.Show();</instruction>
		<instruction>	return progress;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function SearchParams(searchMe, searchExtension, searchStem, excludeFolderName, excludeFolder){</instruction>
		<instruction>	if (searchMe == undefined) searchMe=&apos;iso&apos;;</instruction>
		<instruction>	if (searchExtension == undefined) searchExtension=true;</instruction>
		<instruction>	if (searchStem == undefined) searchStem=false;</instruction>
		<instruction>	if (excludeFolderName == undefined) excludeFolderName=&quot;&quot;;</instruction>
		<instruction>	if (excludeFolder == undefined) excludeFolder=false;</instruction>
		<instruction>	this.searchMe=searchMe;</instruction>
		<instruction>	this.searchExtension=searchExtension;</instruction>
		<instruction>	this.searchStem=searchStem;</instruction>
		<instruction>	this.excludeFolderName=excludeFolderName;</instruction>
		<instruction>	this.excludeFolder=excludeFolder;</instruction>
		<instruction>	this.GetSearchMode = function(){</instruction>
		<instruction>		var searchMode=&apos;full&apos;;</instruction>
		<instruction>		if (this.searchExtension &amp;&amp; !this.searchStem) searchMode=&apos;ext&apos;;</instruction>
		<instruction>		if (!this.searchExtension &amp;&amp; this.searchStem) searchMode=&apos;stem&apos;;</instruction>
		<instruction>		return searchMode;</instruction>
		<instruction>	}</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function GetSearchParamsFromDialog(dlg){</instruction>
		<instruction>	var dlgSearchParams = new SearchParams();</instruction>
		<instruction>	dlgSearchParams.searchMe = dlg.input;</instruction>
		<instruction>	dlgSearchParams.searchExtension = dlg.options(0).state;</instruction>
		<instruction>	dlgSearchParams.searchStem = dlg.options(1).state;</instruction>
		<instruction>	if (defaultSearch.excludeFolderName){ //exclude subfolder name given, so option is present to exclude it</instruction>
		<instruction>		dlgSearchParams.excludeFolder = dlg.options(2).state;</instruction>
		<instruction>	}</instruction>
		<instruction>	return dlgSearchParams;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function ValidateSearchParams(params){</instruction>
		<instruction>	if (!params)</instruction>
		<instruction>		return false;</instruction>
		<instruction>	if (!params.searchExtension &amp;&amp; !params.searchStem){</instruction>
		<instruction>			DOMsgBox(&quot;Folder Selector..&quot;, &quot;You need to select stem or extension or both!&quot;, &quot;Oops!&quot;);</instruction>
		<instruction>			return false;</instruction>
		<instruction>	}</instruction>
		<instruction>	if (params.searchMe==&quot;&quot;){</instruction>
		<instruction>			DOMsgBox(&quot;Folder Selector..&quot;, &quot;You forgot to enter a string to search for!&quot;, &quot;Oops!&quot;);</instruction>
		<instruction>			return false;</instruction>
		<instruction>	}</instruction>
		<instruction>	return true;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function GetDefaultOrLastSearchParams(data){</instruction>
		<instruction>	var search = defaultSearch;</instruction>
		<instruction>	if (data.func.sourcetab.vars.exists(&quot;lastSearch&quot;))</instruction>
		<instruction>		search = Vector2Search(data.func.sourcetab.vars.get(&quot;lastSearch&quot;));</instruction>
		<instruction>	return search;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function GetCombinedSearchParams(data){</instruction>
		<instruction>	var userSearchParams = GetDefaultOrLastSearchParams(data);</instruction>
		<instruction>	var dlg = DoDialog(userSearchParams);</instruction>
		<instruction>	var result=dlg.Show();</instruction>
		<instruction>	if (result==0){</instruction>
		<instruction>		dout(&quot;Folder Selector dialog cancelled.&quot;);</instruction>
		<instruction>		return null;</instruction>
		<instruction>	}</instruction>
		<instruction>	return GetSearchParamsFromDialog(dlg);</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function GetSearchParams(data){</instruction>
		<instruction>	var params = null;</instruction>
		<instruction>	while (!ValidateSearchParams(params)){</instruction>
		<instruction>		params = GetCombinedSearchParams(data);</instruction>
		<instruction>		if (!params)</instruction>
		<instruction>			return false; //dialog canceled</instruction>
		<instruction>	}</instruction>
		<instruction>	return params;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function SaveSearchParams(data, params){</instruction>
		<instruction>	data.func.sourcetab.vars.set(&quot;lastSearch&quot;, Search2Vector(params));</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function Search2Vector( search){</instruction>
		<instruction>	var vector = DOpus.NewVector();</instruction>
		<instruction>	vector.push_back(search.searchMe);</instruction>
		<instruction>	vector.push_back(search.searchExtension);</instruction>
		<instruction>	vector.push_back(search.searchStem);</instruction>
		<instruction>	vector.push_back(search.excludeFolderName);</instruction>
		<instruction>	vector.push_back(search.excludeFolder);</instruction>
		<instruction>	return vector;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function Vector2Search( vector){</instruction>
		<instruction>	return new SearchParams( vector(0), vector(1), vector(2), vector(3), vector(4));</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function DOMsgBox(title,message,buttons){</instruction>
		<instruction>	var dlg = DOpus.Dlg</instruction>
		<instruction>	dlg.window = DOpus.Listers(0);</instruction>
		<instruction>	dlg.message = message;</instruction>
		<instruction>	dlg.title = title;</instruction>
		<instruction>	dlg.buttons = buttons;</instruction>
		<instruction>	var result = dlg.Show();</instruction>
		<instruction>	dout(title+&quot; - &quot;+message+&quot; - &quot;+buttons+&quot; -&gt; &quot;+result);</instruction>
		<instruction>	return result;</instruction>
		<instruction>}</instruction>
		<instruction>///////////////////////////////////////////////////////////////////////////////</instruction>
		<instruction>function dout(text){</instruction>
		<instruction>	DOpus.Output(text);</instruction>
		<instruction>}</instruction>
	</function>
</button>

Enable "search stem" and enter "dvd5", additionally you also might enable "search extension" and enter "dvd5.iso" (will use full filename for search then).
Upper/lowercase does not matter, the search always looks for partial matches, so any wildcards like "*" cannot and shall not be used.

If things like heavy pattern matching is required, the text field could take a regular expression of course, but that won't work for now.

Thank you again. Just tested it, it seems to work. :smiley: :thumbsup:

That's good!.. o)

1 Like

Thanks tbone for this great button script. Great time saver. :thumbsup:

Updated version, v0.2 using regexp search instead of simple ".indexOf()".
For simple searches with simple strings, it should work the same, just notice that you need to escape special characters with this one using a single backslash. "B.B.King (disc1)" should read "B\.B\.King \(disc1\)" e.g.

//thread:
//https://resource.dopus.com/viewtopic.php?f=3&t=21649&start=20#p11694

///////////////////////////////////////////////////////////////////////////////
// Simple dialog based search to select folders.
// Folders will be selected if they contain matching files and at the same
// time do not contain a subfolder (optional).
///////////////////////////////////////////////////////////////////////////////
var version = "0.2";

var defaultSearch = new SearchParams(
   /*search string*/   'iso',
   /*search extension*/   true,
   /*search stem*/      false,
   /*subfolder name*/   'video_ts',
   /*exclude subfolder*/   true
);

var lastSearch = null;
///////////////////////////////////////////////////////////////////////////////
function OnClick(data){
   DOpus.ClearOutput();
   data.func.command.ClearFiles();

   //get enumerator and count of selected folders or complete list of folders
   var folders = GetFolders(data);

   //get a combination of default, last used and current dialog search params
   var params = GetSearchParams(data); if (!params) return; //dialog cancelled

   //save current search params
   SaveSearchParams(data, params);

   //init, open and return progress dialog
   var progress = OpenProgressDialog( data, "Folder Selector..", folders.count);

   var searchMode = params.GetSearchMode();
   while (!folders.enumerator.atEnd() ) {
      var folder = folders.enumerator.item(); folders.enumerator.moveNext();
      dout("Folder ["+folder.name+"]..");
      progress.SetName(folder.name);
      //if subfolder to exclude is given, search subfolders before looking for matching files
      if (params.excludeFolder && defaultSearch.excludeFolderName!="" && SubFolderExists( folder.path+"\\"+folder.name, defaultSearch.excludeFolderName)){
         dout("    Contains subfolder ["+defaultSearch.excludeFolderName+"], skipping folder.");
         progress.StepFiles(1);
         continue;
      }
      if (exists = FileExists( folder.path+"\\"+folder.name, params.searchMe, searchMode)){
         dout("    Contains at least one matching file.");
         data.func.command.AddFile(folder);
      }
      progress.StepFiles(1);
    }

   data.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE");
   progress.Hide();
   DOMsgBox("ISO-FolderSelector","Found "+data.func.command.files.count+" folder(s) matching your search.","Ok");
}
///////////////////////////////////////////////////////////////////////////////
function ReadFolder( path, recurse, exception){
   if (recurse == undefined) recurse=false;
   if (exception == undefined) exception=true;
   var fEnum = DOpus.FSUtil.ReadDir( path, true);
   if (fEnum.error!=0){
      var error = "ReadFolder(): Error reading folder ["+name+"], code ["+fEnum.error+"].";
      if (exception) throw error;
      dout(error);
   }
   return fEnum;
}
///////////////////////////////////////////////////////////////////////////////
function SubFolderExists( folderPath, subFolderName){
   subFolderName = subFolderName.toLowerCase();
   var fEnum = ReadFolder( folderPath, true, true);
   while (!fEnum.complete && (fItem = fEnum.Next()))
      if (fItem.is_dir && (fItem.name.toLowerCase() == subFolderName))
         return true;
   return false;
}
///////////////////////////////////////////////////////////////////////////////
function FileExists( folderPath, searchMe, searchMode){
   if (searchMode == undefined) searchMode='full';
   searchMe = searchMe.toLowerCase();
   if (searchMode=='ext') searchMe=searchMe.replace('\.','');
   var fEnum = ReadFolder( folderPath, true, true);
   while (!fEnum.complete && (fItem = fEnum.Next())){
      if (fItem.is_dir) continue;
      switch (searchMode){
         case 'ext':
            if (fItem.ext.toLowerCase().search("\."+searchMe)!=-1)
               return true;
         break;
         case 'stem':
            if (fItem.name_stem.toLowerCase().search(searchMe)!=-1)
               return true;
         break;
         case 'full':
         default:
            if (fItem.name.toLowerCase().search(searchMe)!=-1)
               return true;
         break;
      }
   }
   return false;
}
///////////////////////////////////////////////////////////////////////////////
function GetFolders(data){
   if (data.func.sourcetab.selected_dirs.count)
      var dirs = data.func.sourcetab.selected_dirs;
   else
      var dirs = data.func.sourcetab.dirs;
   return { enumerator:new Enumerator(dirs), count:dirs.count};
}
///////////////////////////////////////////////////////////////////////////////
function DoDialog( params){
   var dlg = DOpus.Dlg
   dlg.window = DOpus.Listers(0);
   dlg.message = "Please enter string/extension to search for:\n ";
   dlg.title = "Folder Selector..";
   dlg.buttons = "OK|Cancel";
   dlg.icon = "question";

   dlg.max = 128; //enable text field
   dlg['default'] = params.searchMe;

   dlg.options(0).label = "search extension";
   dlg.options(0).state = params.searchExtension;

   dlg.options(1).label = "search stem";
   dlg.options(1).state = params.searchStem;

   if (defaultSearch.excludeFolderName!=""){
      dlg.options(2).label = "shall not contain folder ("+defaultSearch.excludeFolderName+")";
      dlg.options(2).state = params.excludeFolder;
   }
   return dlg;
}
///////////////////////////////////////////////////////////////////////////////
function OpenProgressDialog( data, title, numFiles){
   var progress = data.func.command.progress;
   progress.delay = false;
   progress.abort = true;
   progress.Init(data.func.sourcetab, title);
   progress.AddFiles(numFiles);
   progress.Show();
   return progress;
}
///////////////////////////////////////////////////////////////////////////////
function SearchParams(searchMe, searchExtension, searchStem, excludeFolderName, excludeFolder){
   if (searchMe == undefined) searchMe='iso';
   if (searchExtension == undefined) searchExtension=true;
   if (searchStem == undefined) searchStem=false;
   if (excludeFolderName == undefined) excludeFolderName="";
   if (excludeFolder == undefined) excludeFolder=false;
   this.searchMe=searchMe;
   this.searchExtension=searchExtension;
   this.searchStem=searchStem;
   this.excludeFolderName=excludeFolderName;
   this.excludeFolder=excludeFolder;
   this.GetSearchMode = function(){
      var searchMode='full';
      if (this.searchExtension && !this.searchStem) searchMode='ext';
      if (!this.searchExtension && this.searchStem) searchMode='stem';
      return searchMode;
   }
}
///////////////////////////////////////////////////////////////////////////////
function GetSearchParamsFromDialog(dlg){
   var dlgSearchParams = new SearchParams();
   dlgSearchParams.searchMe = dlg.input;
   dlgSearchParams.searchExtension = dlg.options(0).state;
   dlgSearchParams.searchStem = dlg.options(1).state;
   if (defaultSearch.excludeFolderName){ //exclude subfolder name given, so option is present to exclude it
      dlgSearchParams.excludeFolder = dlg.options(2).state;
   }
   return dlgSearchParams;
}
///////////////////////////////////////////////////////////////////////////////
function ValidateSearchParams(params){
   if (!params)
      return false;
   if (!params.searchExtension && !params.searchStem){
         DOMsgBox("Folder Selector..", "You need to select stem or extension or both!", "Oops!");
         return false;
   }
   if (params.searchMe==""){
         DOMsgBox("Folder Selector..", "You forgot to enter a string to search for!", "Oops!");
         return false;
   }
   return true;
}
///////////////////////////////////////////////////////////////////////////////
function GetDefaultOrLastSearchParams(data){
   var search = defaultSearch;
   if (data.func.sourcetab.vars.exists("lastSearch"))
      search = Vector2Search(data.func.sourcetab.vars.get("lastSearch"));
   return search;
}
///////////////////////////////////////////////////////////////////////////////
function GetCombinedSearchParams(data){
   var userSearchParams = GetDefaultOrLastSearchParams(data);
   var dlg = DoDialog(userSearchParams);
   var result=dlg.Show();
   if (result==0){
      dout("Folder Selector dialog cancelled.");
      return null;
   }
   return GetSearchParamsFromDialog(dlg);
}
///////////////////////////////////////////////////////////////////////////////
function GetSearchParams(data){
   var params = null;
   while (!ValidateSearchParams(params)){
      params = GetCombinedSearchParams(data);
      if (!params)
         return false; //dialog canceled
   }
   return params;
}
///////////////////////////////////////////////////////////////////////////////
function SaveSearchParams(data, params){
   data.func.sourcetab.vars.set("lastSearch", Search2Vector(params));
}
///////////////////////////////////////////////////////////////////////////////
function Search2Vector( search){
   var vector = DOpus.NewVector();
   vector.push_back(search.searchMe);
   vector.push_back(search.searchExtension);
   vector.push_back(search.searchStem);
   vector.push_back(search.excludeFolderName);
   vector.push_back(search.excludeFolder);
   return vector;
}
///////////////////////////////////////////////////////////////////////////////
function Vector2Search( vector){
   return new SearchParams( vector(0), vector(1), vector(2), vector(3), vector(4));
}
///////////////////////////////////////////////////////////////////////////////
function DOMsgBox(title,message,buttons){
   var dlg = DOpus.Dlg
   dlg.window = DOpus.Listers(0);
   dlg.message = message;
   dlg.title = title;
   dlg.buttons = buttons;
   var result = dlg.Show();
   dout(title+" - "+message+" - "+buttons+" -> "+result);
   return result;
}
///////////////////////////////////////////////////////////////////////////////
function dout(text){
   DOpus.Output(text);
}

When i copy the .js file to the opus scripts panel in toolbars scripts it comes up saying "Failed (methods)" what am I doing wrong?

thanks.

The javascript code in the post just above (Jul 19, 2017) is for a Script Button. You can paste it into the button editor.

See the Script Buttons part of this post for instructions:

What you were doing (putting the script in a .js file and dropping it on the Preferences / Toolbars / Scripts page) would be right for a Script Add-In. But the script above is a more simple thing that lives inside a toolbar button.

Got this to work! Thank you for the guidance.

Now that I remember it, here's a related thread with a slightly different method/script, which might be useful if you want to use Tools > Find Files, or filters.

1 Like