// Kind Columns // This is a script for Directory Opus. // See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. // Called by Directory Opus to initialize the script function OnInit(initData) { initData.name = "Kind Columns"; initData.version = "1.1"; initData.copyright = "(c) 2017 Leo Davidson"; initData.url = "https://resource.dopus.com/viewtopic.php?f=35&t=28603"; initData.desc = "Columns for Opus's \"File Type Group\" and Explorer's \"Kind\", for grouping and sorting by high-level types (e.g. Pictures vs separate JPEG and PNG)."; initData.default_enable = true; initData.min_version = "12.3"; var col = initData.AddColumn(); col.name = "FileTypeGroup"; col.method = "OnFileTypeGroup"; col.label = "File Type Group"; col.justify = "left"; col.autogroup = false; var props = DOpus.FSUtil.GetShellPropertyList("System.KindText", "r"); if (props.count == 1) { var prop = props(0); col = initData.AddColumn(); col.name = "Kind"; col.method = "OnKind"; col.label = prop.display_name; // "Kind"; col.justify = "left"; col.autogroup = false; col.userdata = prop.pkey; } } // Implement the FileTypeGroup column function OnFileTypeGroup(scriptColData) { if (scriptColData.item.is_dir) { scriptColData.value = "Folder"; scriptColData.group = "Folder"; } else if (scriptColData.item.ext == ".lnk") { scriptColData.value = "Link"; scriptColData.group = "Link"; } else { var groups = scriptColData.item.groups; if (typeof groups == "object") { if (!groups.empty) { if (groups.count == 1) // Speed up the usual, simple case. { var strGroup = groups(0).display_name; scriptColData.group = strGroup; scriptColData.value = strGroup; } else { // Sort by group display names for consistent results. var vecGroupNames = DOpus.Create.Vector(); for (var i = 0; i < groups.count; ++i) { vecGroupNames.push_back(groups(i).display_name); } vecGroupNames.sort(); var strGroups = vecGroupNames(0); // Group by whatever comes first. There's usually only one group but no hierarchy if an extension is in more than one. scriptColData.group = strGroups; // Add any other groups to the displayed value. for (var i = 1; i < vecGroupNames.count; ++i) { strGroups = strGroups + "; " + vecGroupNames(i); } scriptColData.value = strGroups; } } } } } // Implement the Kind column function OnKind(scriptColData) { var strKind; try { strKind = scriptColData.item.shellprop(scriptColData.userdata); } catch (e) { scriptColData.value = ""; scriptColData.group = ""; return; } if (typeof strKind == "string") { scriptColData.value = strKind; // Kind can have multiple values, separated by ;, with the most significant one first: // https://msdn.microsoft.com/en-us/library/windows/desktop/cc144136(v=vs.85).aspx // Group by the first one, which also seems to be what Explorer does. var posSemi = strKind.indexOf(';'); if (posSemi >= 0) { strKind = strKind.substring(0, posSemi); } scriptColData.group = strKind; } }