Copy files to specific folders

I need to be able to copy the files in the left lister into the right lister in the screenshot below. This is one class and, as the weeks, months, and years go by, I'll need to do with each class. I couldn't figure out how to get part of a {file} to be used as part of the destination. (Note the "English" first name they choose is required in the destination folder name, but we don't want them in the filenames.)


Thanks for your help.

Do you mean that the destination folders (with the English names already added) exist already and you need a way to sort the files on the left into the pre-existing folders on the right? (So it would find a folder that starts with the same first two words of the filename.)

Or does it need to create the folders on the right as well? (If so, where will the English names come from? Would it ask for each student and make you type them in?)

There are a few ways both could be done, but quite different approaches would be needed depending on the exact aim.

This way. I'm already using another button to create the folders where they exist (created by another department). So, at the time I click this new "sorting" button I'm trying to create, the folders with the English names will already exist.

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]

Thanks, Leo. I'll try it out tomorrow at work.

It worked.

Thanks for your help.