由于一些挪威字符,我有一个在.bat (批处理)文件中无法正确运行的xcopy。
这一行是:
xcopy /I /V /H /R /C /Y /K /O /X "G:\P - cad_files\Drawings\163997 Ø1000XØ90 T7-8-9.PDF" "F:\CAD\P - cad_files\Drawings\163997 Ø1000XØ90 T7-8-9.PDF"如果我从批处理文件中运行它,它将失败为"0文件复制“,因为它由于字符集而不正确地翻译源文件。
我尝试过使用chcp更改字符集,以及使用Notepad++并使用各种字符集对其进行编码,但由于在Windows中批量处理的限制,它仍然失败。
因此,我的问题是,如何让上面的行在vbscript中执行并记录xcopy输出?
我试过:
set objShell = CreateObject("wscript.Shell")
strSource = "G:\P - Tdwos_cad_files\Drawings\163997 Ø1000XØ90 T7-8-9.PDF"
strDest = "F:\CAD\P - Tdwos_cad_files\Drawings\163997 Ø1000XØ90 T7-8-9.PDF"
command = "xcopy /I /V /H /R /C /Y /K /O /X " & chr(34) & strSource & chr(34) &chr(32) & chr(34) & strDest & chr(34) & " > F:\testvbs.log 2>&1"
objshell.run command然后执行"cscript test.vbs“
但不幸的是,尽管我将objshell.run更改为wscript.echo,它确实显示了“命令”variable...meaning的适当输出,但它仍然无法工作,它显示了正确的语法。
So...any程序员知道如何在vbscript中正确地运行原来的xcopy行吗?如果您知道如何正确地使用编码在批处理文件中运行它,那也没关系.我只是还没有弄清楚。
发布于 2015-06-11 00:11:25
下一个脚本在下一个条件下与合并的挪威-捷克文件夹和文件名一起工作:
UTF-16LE字节顺序标记编码的脚本,以及下面是注释过的代码片段:
' save the script UTF-16LE encoded with the 0xFFFE byte order mark
' run the script as administrator!
' consider //U option: Use Unicode for redirected I/O from the console
' cscript //U 30767978.vbs
'
option explicit
dim objShell, strSource, strDest, command, cmd, xx
set objShell = CreateObject("wscript.Shell")
strSource = "D:\test\éíáýžřčšě\a Ø1000XØ90 b.txt"
strDest = "D:\test\ěščřžýáíé\a Ø1000XØ90 b.txt"
' chcp does not matter: `dir` as well as `xcopy` work for all
cmd = "%comspec% /U /C chcp 65000 & "
cmd = "%comspec% /U /C chcp 65001 & "
cmd = "%comspec% /U /C chcp 437 & "
cmd = "%comspec% /U /C chcp 852 & "
cmd = "%comspec% /U /C chcp 1250 & "
' chcp supposedly matters for redirected output
command = "dir " & """" & strSource & """ """ & strDest & """" & " & pause "
xx = objShell.Run( cmd & command, 1, true)
command = "xcopy /I /V /H /R /C /-Y /K /O /X " _
& """" & strSource & """ """ & strDest & """" & " & pause "
xx = objShell.Run( cmd & command, 1, true)
Wscript.Echo xx, cmd & command 发布于 2015-06-11 17:40:46
虽然JosefZ接受的答案很好用,但我发现只要简单地将xCopy行从.bat文件移到Powershell .ps1文件并运行它,就可以更容易地处理这些问题。Powershell并不像批处理文件那样对字符集犹豫不决。
因此,我在2003服务器上安装了Powershell,并以这种方式运行脚本,并且运行良好。
我接受了JosefZ的回答,因为它回答了实际的问题,但在这里发布这个问题,以防其他人遇到相同的问题,并希望使用Powershell。
https://stackoverflow.com/questions/30767978
复制相似问题