Mythicsoft Knowledge Base

Full Text Search
»

Automated tasks using the Search Engine

RSS
The FileLocator Pro search engine can be used to help in automated tasks. Using a scripting language, such as JScript, it is possible to perform further operations on found files.

Example: Copying a list of found files to a specific folder


// JScript example that loads a predefined search, runs it, and then copies each
// of the found files to another folder

// 1. Create the FLPro search engine and FileSystemObject

var engineSearch = new ActiveXObject( "FLProCore.SearchEngine" );
var sysFile = WScript.CreateObject("Scripting.FileSystemObject");

// 2. Load a pre-saved search into the search engine and start the search
// (passing false to tell the search engine to not return
// until the search has finished)

engineSearch.SearchCriteria.LoadAll( "e:\\checkfiles.srf" );
var listResult = engineSearch.Start(false);

// 3. Loop through each file and perform the required operation
// (in this case copying the files to a folder called e:\copyhere)

for (n = 0; n < listResult.Count; ++n)
{
	var strFullName = listResult.Item(n).Path + listResult.Item(n).FileName;
	WScript.Echo("Copying: " + strFullName);
	sysFile.CopyFile(strFullName, "e:\\copyhere\\", true /* Overwrite? */ );
}


With this script saved in a file, e.g. e:\search_copy.js you can then run it at the command line or as part of a batch script using the command:

cscript e:\search_copy.js //E:JScript

Mythicsoft KB powered by ScrewTurn Wiki. Some of the icons created by FamFamFam.