The following script, inspired by @aprold's (link), aims to compare the active tabs in both panels and select different files and folders. As it stands, the files are selected correctly, but the folders aren't. Could someone tell me the cause of this problem? Thank you very much.
function OnClick(clickData) {
var srcItems = {}; // Unique items (files and folders) in the left panel
var dstItems = {}; // Unique items (files and folders) in the right panel
var commonItems = {}; // Common elements
// 1. Get information about elements in the left panel
var srcEnum = new Enumerator(clickData.func.sourcetab.files);
while (!srcEnum.atEnd()) {
var item = srcEnum.item();
var key;
if (item.is_dir) {
// For folders: name and size
key = item.name + "|" + item.size;
} else {
// For files: name, size and modification date
key = item.name + "|" + item.size + "|" + item.modify;
}
srcItems[key] = item;
srcEnum.moveNext();
}
// 2. Compare with items in the right panel
var dstEnum = new Enumerator(clickData.func.desttab.files);
while (!dstEnum.atEnd()) {
var item = dstEnum.item();
var key;
if (item.is_dir) {
// For folders: name and size
key = item.name + "|" + item.size;
} else {
// For files: name, size and modification date
key = item.name + "|" + item.size + "|" + item.modify;
}
if (key in srcItems) {
// If element exists in both panels with the same attributes
commonItems[key] = true;
delete srcItems[key]; // We removed it from the only ones on the left panel
} else {
// The element is unique in the right panel
dstItems[key] = item;
}
dstEnum.moveNext();
}
// 3. Select unique items in the left panel
clickData.func.command.ClearFiles();
for (var key in srcItems) {
clickData.func.command.AddFile(srcItems[key]);
}
clickData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH");
// 4. Select unique items in the right panel
clickData.func.command.SetSourceTab(clickData.func.desttab);
clickData.func.command.ClearFiles();
for (key in dstItems) {
clickData.func.command.AddFile(dstItems[key]);
}
clickData.func.command.RunCommand("Select FROMSCRIPT DESELECTNOMATCH");
}