0 votes

FileLocator Pro has been one of my must-have tools at the office for many years, it's a great tool! Having been using it for so many years, I've built up a good number of favorite searches. So when I got a new computer, I copied all the srf files over.

That's great ... except all my paths are on a different drive on the other computer. So I need to update the drive letter on every single one of the favorites. It's really quite painful. I was wondering if you could suggest a way I could update my favorites without doing it one by one by hand? I'm a programmer, so if the srf files are some common file format, I could work with that. I often wish I could bulk update the things, or at least edit them easier.

asked by (57.9k points)

1 Answer

+1 vote

With a little bit of programming you should be able to do that. The following script reads all the SRF files from the root of the E:\ folder and replaces any paths that start with T:\ to Y:\

Step 1. Save the script to a file, e.g. change_lookin.js

Step 2. Change the strRoot value to be the folder you want to run this on, e.g.

var strRoot = "C:\\My\\SRF\\Folder";

Step 3. Run the script at the command prompt

cscript change_lookin.js

The Script:

var criteria = new ActiveXObject( "FLProCore.SearchCriteria" );
var FSO = new ActiveXObject("Scripting.FileSystemObject");

var strRoot = "e:\\";		// The folder to look in

// Enumerate through the files in the folder

var objCurrentFolder = FSO.GetFolder( strRoot);
var objFiles = objCurrentFolder.Files;

var enumFiles = new Enumerator(objFiles);
for (;!enumFiles.atEnd(); enumFiles.moveNext())
{
	// If the file has a .srf extension load it
	// and check the Look In Value
	
	var strName = enumFiles.item().Name;
	if (strName.match(/\.srf$/i))
	{	
		// Load the criteria

		var strFile = FSO.GetAbsolutePathName(enumFiles.item());
		WScript.Echo("File: " + strFile);
		criteria.Load(strFile);
		
		// Globally replace any path that starts with T:\ to Y:\
		
		var strOriginal = criteria.LookIn;
		criteria.LookIn = criteria.LookIn.replace(/T:\\/gi, "Y:\\");
		WScript.Echo("Look In: " + strOriginal);
		
		// If the criteria was changed save the criteria back to the file
		
		if (criteria.LookIn != strOriginal)
		{
			WScript.Echo("-> Changed to: " + criteria.LookIn);
			criteria.Save(strFile);
		}
		else
		{
			WScript.Echo("No change");
		}
	}
}
	
answered by (57.9k points)
...