Commands to copy selected filenames to the clipboard

Clipboard commands in the default configuration:

Directory Opus comes pre-configured with menu items and hotkeys for copying the names and/or paths of selected items to the clipboard.

In the default Edit menu:

In the default right-click context menus:

You can move those around, modify their hotkeys, or add more commands for doing slightly different things.

Adding similar commands to right-click context menus:

If your right-click context menus are missing the default commands, or if you want to add extra commands to them, here is how. We will add the basic Copy File Names item, but you can modify things as needed.

  • In Opus, click Settings > Filetypes...
  • Double-click All Files & Folders, near the top of the list.
  • Select the Context Menu tab.
  • Click New
  • Enter the following information for the new filetype action:
    Action: Copy Names
    Type: Run an Opus function (not supported in Explorer)
    Function: Clipboard COPYNAMES
    (If you click the square next to the action's name, you can also give it an icon if you wish.)
  • Click OK twice to save your changes, then Close to close the Filetypes editor.

If you now select and right-click some files in Opus, you'll find the new command in the context menu.

Specifying what gets put in the clipboard:

You can add arguments to the command to change what is put in the clipboard. For example, you may only want the filenames and not the paths, or you might want UNC paths for files on mapped network drives (since other people may map them via a different drive-letter).

Below are some examples. Refer to the Clipboard command in the manual for full details.

  • Default:
    CLIPBOARD COPYNAMES
    H:\Example_Filename.jpg

  • Filename Only:
    CLIPBOARD COPYNAMES=nopaths
    Example_Filename.jpg

  • Short Paths:
    CLIPBOARD COPYNAMES=short
    H:\EXAMPL~1.JPG

  • URL:
    CLIPBOARD COPYNAMES=url
    file://H:\Example%5fFilename.jpg

  • UNC (network drives):
    CLIPBOARD COPYNAMES=unc
    \\marla\share\Example_Filename.jpg

  • MD5 hash (1):
    CLIPBOARD COPYNAMES=hash
    Example_Filename.jpg : 1224d22982530cde353aa7f6a090ef55

  • MD5 hash (2):
    CLIPBOARD COPYNAMES=hash2
    1224d22982530cde353aa7f6a090ef55 *Example_Filename.jpg

You can use single to make everything appear on a single line instead of one line per file. You can also combine things, for example:

  • Copy the short names, without paths, to a single line:
    Clipboard COPYNAMES=short,nopaths,single

Applying Regular Expressions to the paths:

You can modify what gets placed in the clipboard using regular expressions. Below are some examples. (See RegExp basics: Removing characters from start/end of names if you need help learning the basics of regular expressions.)

  • Copy UNC path with quotes around it:
    Clipboard COPYNAMES=unc REGEXP (.*) ""\1""
    "\\marla\share\Example_Filename.jpg"

  • Copy file names without extensions:
    Clipboard COPYNAMES=nopaths REGEXP (.*)\.[^.]* \1
    H:\Example_Filename

  • Copy paths escaped for C++:
    See separate example.
    \\\\marla\\share\\Example_Filename.jpg

Putting the current folder's path in the clipboard:

To re-create the Folder Path item in the default config, see the separate thread, Copy the current path to the clipboard.

Copy the whole folder listing to the clipboard:

To re-create the Complete Folder Listing item in the default config:

  • Complete Folder Listing:
    Print FOLDER AS=txt TO=clip FLATVIEW=no QUIET

Scripting, for more esoteric needs

For more complicated or esoteric requirements, where the built-in modes and/or regular expressions aren't enough, you can use a script.

For example:


JScript:

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)
{
	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 excluding extensions.
		s += eFiles.item().name_stem_m;
		s += "\n"; // Each name on a new line.
	}

	DOpus.SetClip(s);
}
1 Like