Columns: Extensions for Shortcut Targets

Overview:

This script adds a column which is like the built-in Ext (extension) column, except that if the file is a shortcut it will show the extension of the file the shortcut points to, instead of the actual shortcut extension of "lnk".

Installation and Usage:

  • Download Lnk Extensions.js.txt (1.2 KB)
  • Open Settings > Preferences / Toolbars / Scripts.
  • Drag Link Extensions.js.txt to the list of scripts.

A new column will now be available:

  • Script > Ext

You can display, sort and group using the column the same as you would normal built-in columns. For example, right-click the column header, or use the Folder Options dialog.

You can also refer to the column in commands which you can place on toolbar buttons, menu items, hotkeys, etc.:

Set COLUMNSTOGGLE="scp:Lnk Extensions/Ext"

History:

1.0 (30/Oct/2018):

  • Initial version.

Script code:

The script code from the download above is reproduced below. This is for people browsing the forum for scripting techniques. You do not need to care about this code if you just want to use the script.

// Lnk Extensions
// (c) 2018 Leo Davidson

// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.

function OnInit(initData)
{
	initData.name = "Lnk Extensions";
	initData.version = "1.0";
	initData.copyright = "(c) 2018 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/columns-extensions-for-shortcut-targets/30364";
	initData.desc = "Ext column for shortcut targets";
	initData.default_enable = true;
	initData.min_version = "12.10";

	var col = initData.AddColumn();
	col.name = "Ext";
	col.method = "OnExt";
	col.label = "Ext";
	col.justify = "left";
	col.autogroup = false;
}

function OnExt(scriptColData)
{
	var ext = scriptColData.item.ext_m;

	if (ext != "" && ext[0] == ".")
		ext = ext.substr(1);
	ext = ext.toLowerCase();

	if (ext == "lnk")
	{
		var sh = new ActiveXObject("WScript.Shell");
		var sc = sh.CreateShortcut(scriptColData.item.realpath);
		var targetItem = DOpus.FSUtil.GetItem(sc.TargetPath);

		ext = targetItem.ext_m;

		if (ext != "" && ext[0] == ".")
			ext = ext.substr(1);
		ext = ext.toLowerCase();
	}

	scriptColData.value = ext;
	scriptColData.group = ext;
}