Text Replace for folder path copied

Putting more than one line per file into the clipboard is probably too much for the Clipboard command. A little script can help:

// https://resource.dopus.com/t/text-replace-for-folder-path-copied/40055

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

    if (tab.selected_dirs.count == 0) return;

    var tmp = '';
    for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        var stdPath = String(item.realpath).replace(/^C:\\User\\huangb/, '%userprofile%');
        tmp += 'EN:\r\n';
        tmp += stdPath + '\r\n';
        tmp += 'DE:\r\n';
        tmp += stdPath.replace(/Documents/, 'Documente') + '\r\n';
        tmp += '\r\n';
    }

    DOpus.SetClip(tmp);

    // cmd.RunCommand('Set UTILITY=otherlog');
    // DOpus.ClearOutput();
    // DOpus.Output(tmp);
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Text Replace For Folder Path Copied</label>
	<icon1>#clipcopy</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/text-replace-for-folder-path-copied/40055</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (tab.selected_dirs.count == 0) return;</instruction>
		<instruction />
		<instruction>    var tmp = &apos;&apos;;</instruction>
		<instruction>    for (var e = new Enumerator(tab.selected_dirs); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        var stdPath = String(item.realpath).replace(/^C:\\User\\huangb/, &apos;%userprofile%&apos;);</instruction>
		<instruction>        tmp += &apos;EN:\r\n&apos;;</instruction>
		<instruction>        tmp += stdPath + &apos;\r\n&apos;;</instruction>
		<instruction>        tmp += &apos;DE:\r\n&apos;;</instruction>
		<instruction>        tmp += stdPath.replace(/Documents/, &apos;Documente&apos;) + &apos;\r\n&apos;;</instruction>
		<instruction>        tmp += &apos;\r\n&apos;;</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    DOpus.SetClip(tmp);</instruction>
		<instruction />
		<instruction>    // cmd.RunCommand(&apos;Set UTILITY=otherlog&apos;);</instruction>
		<instruction>    // DOpus.ClearOutput();</instruction>
		<instruction>    // DOpus.Output(tmp);</instruction>
		<instruction>}</instruction>
	</function>
</button>

1 Like