I think this should do what you want:
-
Dupes Special.dcf (5.7 KB)
-
See How to use buttons and scripts from this forum
(Go to the Button .dcf Files section, if it doesn't jump to it directly).
For reference, here's the script code which is inside the toolbar button:
function OnClick(clickData)
{
// Change this to change the collection name it outputs to.
// It'll add the starting folder name to the end.
// WARNING: Will go haywire if you run the button twice in parallel!
var Collection_Name = "Dupes Special";
var resPath = DOpus.FSUtil.Resolve(clickData.func.sourcetab.path);
Collection_Name += " - " + resPath.filepart;
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.ClearFiles();
var mapNamesToVecPaths = DOpus.Create.Map();
// r = Recursive
// l = Skip junctions and symbolic links
var folderEnum = DOpus.FSUtil.ReadDir(resPath, "rl");
while (!folderEnum.complete)
{
var folderItem = folderEnum.Next();
if (folderItem.is_dir)
{
continue; // Skip directories.
}
var name = folderItem.name_stem_m; // Separate stem from extension.
name = name.replace(/^(.+) \(.+\)$/, "$1"); // Remove " (*)" at the end of the stemp.
name += folderItem.ext_m; // Add extension back.
name = name.toUpperCase(); // Uppercase everything so the map ignores case.
// DOpus.Output(name + ' - ' + folderItem);
if (!mapNamesToVecPaths.exists(name))
{
mapNamesToVecPaths(name) = DOpus.Create.Vector();
}
mapNamesToVecPaths(name).push_back(folderItem.realpath);
// DOpus.Output(name + ' = ' + mapNamesToVecPaths(name).count);
}
for (var e = new Enumerator(mapNamesToVecPaths); !e.atEnd(); e.moveNext())
{
var vecPaths = mapNamesToVecPaths(e.item());
if (vecPaths.size > 1)
{
cmd.AddFiles(vecPaths);
}
}
// DOpus.Output(cmd.filecount)
var colPath = 'coll://' + Collection_Name;
// Delete any existing collection.
// Create a new blank collection.
// Add the found items to it.
cmd.AddLine('Delete QUIET FILE="' + colPath + '"');
cmd.AddLine('CreateFolder READAUTO=no NAME="' + colPath + '"');
cmd.AddLine('Go PATH="' + colPath + '" NEWTAB=findexisting');
cmd.Run();
// Now add the found items (if any) to the collection.
// This needs to be done as a separate command to the three above.
if (cmd.filecount > 0)
{
cmd.RunCommand('Copy TO="' + colPath + '" COPYTOCOLL=member');
}
}