Before clicking the button:
After clicking the button:
The button as a .dcf file (How to add buttons from this forum to your toolbars):
Copy to Student Name Folders.dcf (2.44 KB)
The script code, for reference (also contained in the .dcf file above):
[code]@script JScript
function OnClick(clickData)
{
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
cmd.ClearFiles(); // Command object should ignore selection (we'll specify paths as arguments)
var destPath = clickData.func.desttab.path;
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
var fileDestPath = GetDestPath(eSel.item().name_stem, destPath);
cmd.RunCommand("Copy \"" + eSel.item().realpath + "\" TO \"" + fileDestPath + "\"");
}
}
function GetDestPath(fileName, destPath)
{
var folderEnum = DOpus.FSUtil.ReadDir(destPath, false);
var fileNameUpper = new String(fileName).toUpperCase();
while (!folderEnum.complete)
{
var folderItem = folderEnum.next;
var folderName = new String(folderItem.name_stem);
var namePart = folderName.replace(/^(.+) \(.*\)$/, "$1");
var namePartUpper = namePart.toUpperCase();
if (fileNameUpper.indexOf(namePartUpper) === 0
&& (fileNameUpper.length === namePartUpper.length
|| fileNameUpper[namePartUpper.length] === " "))
{
return folderItem.realpath;
}
}
return destPath;
}[/code]