Is there a way to compare folder structures between 2 listers? I want to ignore files and simply compare directory/subdir names.
If you mean compare two tabs, this script may prove helpful:
function OnInit(data) {
var cmd = data.AddCommand();
cmd.name = "CompareTabs";
cmd.method = "OnCompareTabs";
cmd.label = data.name = "Compare Tabs";
cmd.desc = data.desc = "Compare tabs in dual display mode and select files differing in name or size.";
cmd.template = "SAME/S";
data.default_enable = true;
return false;
}
function OnCompareTabs(data) {
var lister = data.func.sourcetab.lister; // get lister object from source tab
if (!lister.dual) return; // do nothing if not in dual panel mode
var src = {}, dst = {}, dup = {};
var SelCmd1 = "Select FROMSCRIPT DESELECTNOMATCH";
var SelCmd2 = "Select INVERT TYPE=Files";
// add all files from source tab to src array
var srcEnum = new Enumerator(lister.activetab.files);
while (!srcEnum.atEnd()) {
var item = srcEnum.item();
src[item.name] = item;
srcEnum.moveNext();
}
// add different files from destination tab to dst array and others to dup array
var dstEnum = new Enumerator(lister.desttab.files);
while (!dstEnum.atEnd()) {
item = dstEnum.item();
if (!(item.name in src) || (src[item.name].size - item.size)) dst[item.name] = item;
else dup[item.name] = item;
dstEnum.moveNext();
}
// add files from src that are not in dup to select command
data.func.command.ClearFiles();
for (var k in src) if (!(k in dup)) data.func.command.AddFile(src[k]);
// Select DIFFERENT files
data.func.command.RunCommand(SelCmd1);
// Invert selection if user requested SAME instead of (default) DIFFERENT
if (data.func.args.got_arg.same) data.func.command.RunCommand(SelCmd2);
// add all files from dst to select command
data.func.command.SetSourceTab(lister.desttab);
data.func.command.ClearFiles();
for (k in dst) data.func.command.AddFile(dst[k]);
// Select DIFFERENT files
data.func.command.RunCommand(SelCmd1);
// Invert selection if user requested SAME instead of (default) DIFFERENT
if (data.func.args.got_arg.same) data.func.command.RunCommand(SelCmd2);
}
Button:
<?xml version="1.0"?>
<button backcol="none" display="both" separate="yes" textcol="none">
<label> Compare Tabs</label>
<tip>Compare Tab contents and highlight differences\nCTRL: Compare tab contents and highlight same files</tip>
<icon1>#Line Icons - Dark:syncpane1</icon1>
<function type="normal">
<instruction>@keydown:none</instruction>
<instruction>CompareTabs</instruction>
<instruction>@keydown:ctrl</instruction>
<instruction>CompareTabs SAME</instruction>
</function>
</button>
I fixed the button xml in your post so it displays properly on the forum.
But I don’t think the post is useful without more information about what all that code does, and how to use it.
If it comes from a forum post, linking to the original thread is better than duplicating the source without all the context around it.
For the original post, see Compare tab contents in dual display mode
3 Likes
Thanks for pointing this out. I will make sure to be more clear next time.
1 Like