Bryan.H
December 12, 2021, 11:40am
1
Hi, Dears,
I am asking for a quick help: I want to achieve that maybe I can set up a new button in DOpus and it'll copy the current file/folder's full path, but replace my username part into a general approach, i.e. change "C:\Users\bryan" into "%userprofile%".
I have already searched in here, and got below page really alike my need.
https://resource.dopus.com/t/replace-text-in-clipboard/9969
However my ability of RegExp is really not enough for me.
So far I tried
Clipboard COPYNAMES=unc REGEXP "^C:\Users\bryan(.)*$" "%userprofile%\2"
It doesn't work.
Can anybody help, please.
thank you.
lxp
December 12, 2021, 12:08pm
2
Try
@noexpandenv
Clipboard COPYNAMES=unc REGEXP "C:\\Users\\bryan(.*)" "%userprofile%\1"
Bryan.H
December 13, 2021, 7:39am
3
Super! works like a charm.
Thanks a lot.
Hello, I hope I can ask by attaching to this solved question:
if I copy the OneDrive Path, natively from Windows it'll be:
C:\Users\huangb\COMPANY NAME\Teams Folder - Documents\....
@lxp gave a perfect help on the issue of replacing my username into non-specific one.
with his script, I can end up like:
%Userprofile%\COMPANY NAME\Teams Folder - Documents\...
But then I found further trouble:
I am in English language, and my colleagues in German environment got this in their local folder:
%Userprofile%\COMPANY NAME\Teams Folder - Documen**te**\...
Annoying!
My question now, can I get the script into:
EN:
%Userprofile%\COMPANY NAME\Teams Folder - Documen**ts**\...
DE:
%Userprofile%\COMPANY NAME\Teams Folder - Documen**te**\...
with two rows automatically. I am struggling with it without success.
Thanks.
Leo
April 27, 2022, 8:59am
5
If you turn off Preferences / Folders / Folder Display / Display localized folder names , you'll probably see the folder's real name, which is probably the same in all languages.
lxp
April 27, 2022, 11:19am
6
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 = '';</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/, '%userprofile%');</instruction>
<instruction> tmp += 'EN:\r\n';</instruction>
<instruction> tmp += stdPath + '\r\n';</instruction>
<instruction> tmp += 'DE:\r\n';</instruction>
<instruction> tmp += stdPath.replace(/Documents/, 'Documente') + '\r\n';</instruction>
<instruction> tmp += '\r\n';</instruction>
<instruction> }</instruction>
<instruction />
<instruction> DOpus.SetClip(tmp);</instruction>
<instruction />
<instruction> // cmd.RunCommand('Set UTILITY=otherlog');</instruction>
<instruction> // DOpus.ClearOutput();</instruction>
<instruction> // DOpus.Output(tmp);</instruction>
<instruction>}</instruction>
</function>
</button>
This post explains how to add buttons to toolbars and menus, and also applies to raw commands for things like standalone hotkeys.
For how to use Script Add-Ins, please scroll down to see the post below this one.
Much of this assumes Directory Opus…
1 Like
Hey, Leo,
thanks for reply.
Yes I've thought about it, but I think this is generated automatically when I click SharePoint "Sync to Local" Button, i.e. not relavent to the "Localized folder name" topic. -- But obivously the same philosophy from Microsoft was there.
Again works great!
minor issue exist in
var stdPath = String(item.realpath).replace(/^C:\\User\\huangb/, '%userprofile%');
the replacing wasn't successful.
But I'll take this as my home work, in case I fail eventually I'll come to you again.
Big Thanks!
lxp
April 27, 2022, 5:03pm
9
Yes, there seems to be an s missing.
1 Like
Dear Lxp,
Unfortunatenly my further mod failed based on your work.
I want to set up an "if logic" to only do the EN/DE variant when there is "Documents" showing up in the path. So I tried below (with googling JScript "Includes" event).
// 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:\\Users\\huangb/, '%userprofile%');
DOpus.output(stdPath)
var result=String(stdPath).includes('Documents');
if(result){
tmp += 'EN:\r\n';
tmp += stdPath + '\r\n';
tmp += 'DE:\r\n';
tmp += stdPath.replace(/Documents/, 'Dokumente') + '\r\n';
tmp += '\r\n';
}else{
tmp += stdPath
}
}
DOpus.SetClip(tmp);
// cmd.RunCommand('Set UTILITY=otherlog');
// DOpus.ClearOutput();
// DOpus.Output(tmp);
}
Could you kindly again help, please?
Much appreciated!
Leo
April 28, 2022, 3:17pm
11
Untested, but I think this should work:
// 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:\\Users\\huangb/, '%userprofile%');
var altPath = stdPath.replace(/Documents/, 'Dokumente');
// DOpus.output(stdPath)
if(stdPath != altPath) {
tmp += 'EN:\r\n';
tmp += stdPath + '\r\n';
tmp += 'DE:\r\n';
tmp += altPath;
tmp += '\r\n\r\n';
} else {
tmp += stdPath
tmp += '\r\n';
}
}
DOpus.SetClip(tmp);
}
2 Likes
lxp
April 28, 2022, 3:32pm
12
Bryan.H:
JScript "Includes" event
I am afraid JScript doesn't support includes()
. You could use indexOf()
instead, but Leo's solution should be just fine.
1 Like
Sorry for coming back again:
I came to realize that the script only works for "folder/dir", but not "files".
I think it's coming from
new Enumerator(tab.selected_dirs)
but if I swtich to tab.selected_files, it still doesn't work.
How can we fix this please?
Leo
May 2, 2022, 6:26am
16
selected
will give you both files and folders, if both is what you want.
1 Like
Hi, Leo,
yes I want both and yes it works.
Thanks again!