[Directory Opus]对下载的文件名乱码进行编码/解码

DO按钮配置代码=>复制代码后在工具栏自定义后粘贴即可

<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label> URI编码/解码</label>
	<tip>对下载的文件名乱码进行编码/解码</tip>
	<icon1>#pathfield</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData)</instruction>
		<instruction>{</instruction>
		<instruction />
		<instruction>	DOpus.ClearOutput();</instruction>
		<instruction>	// --------------------------------------------------------</instruction>
		<instruction>	var cmd = clickData.func.command;</instruction>
		<instruction>	cmd.deselect = false; // Prevent automatic deselection</instruction>
		<instruction>	// --------------------------------------------------------</instruction>
		<instruction>	// cmd.RunCommand(&quot;Set VIEW=Details&quot;);</instruction>
		<instruction>	// --------------------------------------------------------</instruction>
		<instruction />
		<instruction>	if (clickData.func.sourcetab.selected.count == 0)</instruction>
		<instruction>	{</instruction>
		<instruction>		DOpus.Output(&quot;  (none)&quot;);</instruction>
		<instruction>	}</instruction>
		<instruction>	else</instruction>
		<instruction>	{</instruction>
		<instruction>		for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())</instruction>
		<instruction>		{</instruction>
		<instruction>		DOpus.Output(&quot;  (none)&quot;+eSel.item().name.indexOf(&quot;%&quot;));</instruction>
		<instruction />
		<instruction>				if (eSel.item().name.indexOf(&quot;%&quot;)&gt;-1)</instruction>
		<instruction>				{</instruction>
		<instruction>					var coded=decodeURIComponent(eSel.item().name.replace(/\+/g,  &quot; &quot;));</instruction>
		<instruction>					cmd.RunCommand(&apos;rename to &quot;&apos;+coded+&apos;&quot;&apos;);</instruction>
		<instruction>					DOpus.Output(&apos;解&apos;+coded);</instruction>
		<instruction>				}</instruction>
		<instruction>				else</instruction>
		<instruction>				{</instruction>
		<instruction>					var coded=encodeURIComponent(eSel.item().name).replace(/&apos;/g,&quot;%27&quot;).replace(/&quot;/g,&quot;%22&quot;);	</instruction>
		<instruction>					cmd.RunCommand(&apos;rename to &quot;&apos;+coded+&apos;&quot;&apos;);</instruction>
		<instruction>					DOpus.Output(&apos;加&apos;+coded);</instruction>
		<instruction>				}</instruction>
		<instruction>		}</instruction>
		<instruction>	}</instruction>
		<instruction />
		<instruction>}</instruction>
	</function>
</button>

功能代码=>JScript

function OnClick(clickData)
{

	DOpus.ClearOutput();
	// --------------------------------------------------------
	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection

	if (clickData.func.sourcetab.selected.count == 0)
	{
		DOpus.Output("  (none)");
	}
	else
	{
		for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
		{
		DOpus.Output("  (none)"+eSel.item().name.indexOf("%"));

				if (eSel.item().name.indexOf("%")>-1)
				{
					var coded=decodeURIComponent(eSel.item().name.replace(/\+/g,  " "));
					cmd.RunCommand('rename to "'+coded+'"');
					DOpus.Output('解'+coded);
				}
				else
				{
					var coded=encodeURIComponent(eSel.item().name).replace(/'/g,"%27").replace(/"/g,"%22");	
					cmd.RunCommand('rename to "'+coded+'"');
					DOpus.Output('加'+coded);
				}
		}
	}

}

======================

T

猜你喜欢

转载自blog.csdn.net/yuan6319/article/details/83050798