Change network filepath to mapped drive filepath

When DO displays a network path above the file list (in my case "\SERVER01\DriveZ\whatever...") I would like to be able to click a button to change the path to its mapped drive equivalent "Z:\whatever...". I can do this manualy (delete "\SERVER01\Drive" and add a colon after the Z) but a button would be great. Can anyone asssist with the required code to be applied to a button?

This will toggle between the mapped drive path and the UNC path:

Toggle UNC.dcf (2.3 KB)

function OnClick(clickData)
{
	var curPath    = clickData.func.sourcetab.path + "\\";
	var curPath_UC = curPath.toUpperCase();
	var objNetwork = new ActiveXObject("WScript.Network");
	var drives     = objNetwork.EnumNetworkDrives();
	var newPath    = "";

	for (i = 0; i < drives.length; i += 2)
	{
		var driveLetter    = drives.Item(i  ) + "\\";
		var driveLetter_UC = driveLetter.toUpperCase();
		var driveUNC       = drives.Item(i+1) + "\\";
		var driveUNC_UC    = driveUNC.toUpperCase();

		if (curPath_UC.substr(0,driveLetter_UC.length) == driveLetter_UC)
		{
			newPath = driveUNC + curPath.substr(driveLetter.length);
			break;
		}
		else if (curPath_UC.substr(0,driveUNC_UC.length) == driveUNC_UC)
		{
			newPath = driveLetter + curPath.substr(driveUNC.length);
			break;
		}
	}

	if (newPath != "")
	{
		var cmd = clickData.func.command;
		cmd.ClearFiles();
		cmd.RunCommand('Go PATH="' + newPath + '"');
	}
}
1 Like

Leo, thanks for the rapid repsonse, and a better solution than I was asking for. I'll try it today and report back.
Cheers
Bill

A handy button! Thank you Leo! o)

Not necessarily for me, I use UNC whenever possible, but many co-workers still hang on to mapped drive letters and they never know what actual network paths the mapped drives refer to.

This will help them! o)

1 Like

Hi Leo, thanks again. it works well, but there is a behaviour I don't understand. If the path starts out as \\SERVER01\DriveZ\whatever... after operating the script it becomes Z:\WHATEVER.... That is, the path is converted to uppercase, and appears to be that way in the folder tree view. If I then use F5 to refresh, the path is shown again as the original mixed case.
I can see that this is a deliberate part of your code (var driveUNC = (drives.Item(i+1) + \\").toUpperCase())
but I don't understand why it is necessary, and I continue to be confused and a bit concerned every time I use it, in case it has actually changed the filepath Case. Is this case change necessary?

I've updated the button/script above so it preserves case.

Normally you don't have to worry about that, as Opus checks the case and corrects it to the canonical case from the filesystem, but it looks like we avoid doing that on network drives for performance reasons.

The script only uppercases things so it can compare strings case-insensitive.

Many thanks, Leo, that works perfectly now.

1 Like