Unicode 命名的文件夹显示?在 wscript 提示符下
我遇到 Unicode 命名文件夹的问题。当我将文件夹拖到脚本中时,它没有正确显示文件夹的路径。
简单的VBScript(这只是其中的一部分):
Dim Wshso : Set Wshso = WScript.CreateObject("WScript.Shell")
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count = 1 Then
If FSO.FileExists(Wscript.Arguments.Item(0)) = true and FSO.FolderExists(Wscript.Arguments.Item(0)) = false Then
Alert "You dragged a file, not a folder! My god." & vbcrlf & "Script will terminate immediately", 0, "Alert: User is stupid", 48
WScript.Quit
Else
targetDir = WScript.Arguments.Item(0)
Wshso.Popup targetDir
End If
Else
targetDir = Wshso.SpecialFolders("Desktop")
Alert "Note: No folder to traverse detected, default set to:" & vbcrlf & Wshso.SpecialFolders("Desktop"), 0, "Alert", 48
End If
如果是没有Unicode字符的普通路径就可以了。但在这种情况下:
目录:4Minute (포미닛) - Hit Your Heart
然后它会显示类似 4Minute (?) - Hit Your Heart
如果我做一个FolderExists它找不到拖动的文件夹。
是否有任何解决方法来支持 Unicode 命名文件夹?
谢谢!
如果这还不够清楚,我会编辑
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这似乎确实是 Windows 脚本宿主 DropHandler shell 扩展。然而:
当从控制台键入时,两者都可以工作(即使控制台无法呈现韩文,因此它看起来像
?
),拖放操作应该会导致相同的命令通过 Unicode ->ANSI->Unicode 转换会丢失当前 ANSI 代码页中不存在的所有字符。 (因此포미닛
将适用于默认的韩语 Windows 安装,但不适用于西语。)我不知道解决该问题的正确方法。您也许可以通过更改注册表中 .vbs 文件的 DropHandler 来解决此问题:
从 WSH DropHandler (
{60254CA5-953B-11CF-8C96-00AA00B8708C}
) 到{86C86720-42A0 -1069-A2E8-08002B30309D}
,用于 .exe、.bat 和类似文件的,不会出现此问题。您可能还需要更改 .vbs 的文件关联,以便在文件名参数周围加上引号,因为 EXE DropHandler 不会这样做,以避免文件名中出现空格问题。由于这会影响所有 VBS 文件的参数传递,因此部署在除您自己的计算机之外的任何计算机上都是一个危险的修复。如果您需要这样做,也许您可以尝试使用适当的 DropTarget 创建一个新的文件扩展名,而不是更改 VBSFile 本身?或者也许放弃拖放到脚本上的行为并提供文件打开对话框或手动拖放字段。
This does seem to be a problem peculiar to the Windows Script Host's DropHandler shell extension. Whereas:
both work when typed from the console (even if the console can't render the Hangul so it looks like
?
), a drag and drop operation that should result in the same command goes through a Unicode->ANSI->Unicode translation that loses all characters that aren't in the current ANSI code page. (So포미닛
will work on a default Korean Windows install but not Western.)I'm not aware of a proper way to fix the problem. You could perhaps work around it by changing the DropHandler for .vbs files in the registry:
from the WSH DropHandler (
{60254CA5-953B-11CF-8C96-00AA00B8708C}
) to{86C86720-42A0-1069-A2E8-08002B30309D}
, the one used for .exe, .bat and similar, which doesn't suffer from this issue. You would also probably have to change the file association for .vbs to put quotes around the filename argument too, since the EXE DropHandler doesn't, to avoid problems with spaces in filenames.Since this affects argument-passing for all VBS files it would be a perilous fix to deploy on any machine but your own. If you needed to do that, maybe you could try creating a new file extension with the appropriate DropTarget rather than changing VBSFile itself? Or maybe forgo drop-onto-script behaviour and provide a file Open dialog or manual drop field instead.
对于从 Google 登陆这里的任何人...
Bobince 的提示引导我通过将 vbscript 文件 (myscript.vbs) 包装在 dos 批处理文件 (mybatch.bat) 中来解决此问题。
提示是:
mybatch.bat 包含:
您可能还会发现我的 myscript.vbs 中的这段代码很有帮助
For anyone landing here from Google...
Bobince's tip lead me to work around this problem by wrapping my vbscript file (myscript.vbs) in a dos batch file (mybatch.bat).
The tip was:
mybatch.bat contains:
You may also find this code from my myscript.vbs to be helpful
根据DG的回答,如果您只想接受一个文件作为放置目标,那么您可以编写一个批处理文件(如果您将其命名为“x.bat”,请将文件名为“x.bat.vbs”的VBScript放置在同一文件夹中)仅包含:
@ 表示不在显示屏上输出该行(我发现即使您使用 chcp 1250 作为第一个命令,它也会显示垃圾文本)
不要在 %1 周围使用双引号,如果您的 VBScript 使用如下逻辑(我下面使用的代码来自 http://jeffkinzer.blogspot.com/2012/06/vbscript-to-convert-excel-to-csv.html)。测试了一下,它可以很好地处理文件和文件夹名称中的空格:
Based on DG's answer, if you just want to accept one file as drop target then you can write a batch file (if you have it named as "x.bat" place VBScript with filename "x.bat.vbs" at same folder) that just contains:
the @ means to not output the row on the display (I found it to show garbage text even if you use chcp 1250 as first command)
don't use double-quotes around %1, it won't work if your VBScript uses logic like the following (code I was using below was from http://jeffkinzer.blogspot.com/2012/06/vbscript-to-convert-excel-to-csv.html). Tested it and it works fine with spaces in the file and folder names:
将 WSH DropHandler ({60254CA5-953B-11CF-8C96-00AA00B8708C}) 修改为 {86C86720-42A0-1069-A2E8-08002B30309D} 并添加此函数以将短路径转换为长路径:
Modify WSH DropHandler ({60254CA5-953B-11CF-8C96-00AA00B8708C}) to {86C86720-42A0-1069-A2E8-08002B30309D} and add this function to convert short path to long: