Hi!
Is there a way to easily update file collections to remove items that no longer exist under the specified path (moved, deleted)?
Every once in a while, when I look at old collections, they may contain references to files that are long gone and I can't see a way to prune the lists
Are the files local or on a network drive?
Local, usually
Here's a button which should take care of it. Go into to a collection and click it, and it will make a list of items which don't exist and then remove them from the collection:
Script code for reference
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.ClearFiles();
var fsu = DOpus.FSUtil();
for (var e = new Enumerator(clickData.func.sourcetab.all); !e.atEnd(); e.moveNext())
{
var item = e.item();
if (fsu.Exists(item.RealPath))
{
continue; // Skip items that exist. (This also skips sub-collections.)
}
cmd.AddFile(item);
}
if (cmd.files.count)
{
cmd.RunCommand("Delete REMOVECOLLECTION");
}
}
If network paths are involved, and the servers are offline, it might run much slower as there can be a 30 second timeout before Windows decides a server isn't contactable. But it should still work in the end, and the delay should only happen once for each server (or not at all if Windows has recently cached the fact it's not available).
If needed, you could edit the code to output to the Script Log what it's going to remove, without removing anything at the end, if you want to check the logic makes sense for your collection:
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.ClearFiles();
var fsu = DOpus.FSUtil();
for (var e = new Enumerator(clickData.func.sourcetab.all); !e.atEnd(); e.moveNext())
{
var item = e.item();
if (fsu.Exists(item.RealPath))
{
continue; // Skip items that exist. (This also skips sub-collections.)
}
cmd.AddFile(item);
DOpus.Output("Want to remove: " + item);
}
if (cmd.files.count)
{
// cmd.RunCommand("Delete REMOVECOLLECTION");
}
else
{
DOpus.Output("Nothing to remove.");
}
}
Alternative buttons which let you see which items don't exist before doing anything, if you prefer to do it in two actions and know which files are affected before making any changes.
-
Selects the items that don't exist, deslecting everything else. The first selected item will then be scrolled into view:
Select Non-Existent.dcf (2.7 KB)
-
Hides all items that exist, leaving only the items that don't exist visible:
Show Only Non-Existent.dcf (2.7 KB)
With those, you can use the Remove From Collection command in the files' right-click context menu to remove them if you're happy with the selection. (Also available via the Delete button's menu part, on the default toolbars.)
Both alternative buttons have the same code as the original button, except for running a different command at the end (to select or hide items, rather than remove them immediately).