COPYNAMES, copy name and filesize to clipboard

I'm sorry this is a trivial question, but I haven't learned how to write scripts in DOpus yet. I'm using the basic COPYNAMES command but how I can get the size of each file to be listed alongside the name?

<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>copy as names only</label>
	<tip>Copies the names of all selected files to the clipboard</tip>
	<function type="normal">
		<instruction>Clipboard COPYNAMES=nopaths</instruction>
	</function>
</button>

Please link your account.

I tried to link my account but it says I'm already linked to another account, so it must be a really old account I stopped using years ago and don't have access to anymore.

Looks like mikebanana is your old account. I can reset the email/password on it, or unlink it so you can link your registration to this account. Whichever you prefer.


For the thing you're trying to do, if you only need to do it once or twice, the easiest thing is to use Tools > Print / Export Folder Listing, which can put any details you want into the clipboard. (The CSV format is usually best, as then you don't have to worry about how wide anything is, and you can load the data directly into Excel or Google Sheets.)

If you want to do it frequently, a script is probably the way to go. I can write that for you if you give some more detail. For example, what units and format do you want the sizes to be in, and do you need fixed column widths, or quotes around filenames, or similar?

Wow, thanks. That's a blast from the past. Unlinking would be easiest.

Just looking for something simple like
filename xxMB

No need for any other formatting.

I've moved the account linking over.


Here's a button which should do what you've asked for:

If anything is selected, it will just do the selection.

If nothing is selected, it will do the whole folder.


For reference, this is the script code inside the .dcf file above:

function OnClick(clickData)
{
	clickData.func.command.deselect = false;
	tab = clickData.func.sourcetab;

	if (tab.selected.count == 0)
	{
		// Nothing selected? Do the whole folder.
		NamesToClipboard(tab.dirs, tab.files);
	}
	else
	{
		// Something selected? Do just the selection.
		NamesToClipboard(tab.selected_dirs, tab.selected_files);
	}
}

function NamesToClipboard(dirs, files)
{
	var fsu = DOpus.FSUtil;
	var s = "";

	for (var eDirs = new Enumerator(dirs); !eDirs.atEnd(); eDirs.moveNext())
	{
		// Directory names as-is.
		s += eDirs.item().name;
		s += "\n"; // Each name on a new line.
	}

	for (var eFiles = new Enumerator(files); !eFiles.atEnd(); eFiles.moveNext())
	{
		// File names and sizes in MB.
		var i = eFiles.item();
		var z = fsu.NewFileSize(i.size);
		z.Div(1024*1024);
		s += i.name;
		s += " ";
		s += z.val;
		s += "MB \n"; // Each name on a new line.
	}

	DOpus.SetClip(s);
}

Script is adapted from Commands to copy selected filenames to the clipboard (which didn't include the size originally).

Thanks, this is very helpful. I will use your script as a study model. I tested it and it didn't quite work. It gave "undefinedMB" instead of the size.

FWIW, I tested it with Opus 12.30, in the Opus Program Files directory.

I was on Opus 12.20. I upgraded to 12.30 and now it works!

1 Like

Any hints on how to modify it to get folder sizes listed too?

Here's some script code that will calculate the size of a folder:

Thanks, I'll play with this and learn more about scripting.