0

中文字符不能通过 VBScript 保存在文本文件中。

VBScript在一个中文名称为:视窗的文件夹中。该脚本将创建一个文本文件,其中将显示当前工作目录。中文字符不能保存在文件中。Windows 脚本宿主说“错误:无效的过程调用或参数”。如果文件夹名称为英文,则不会出现此错误。

Path = CreateObject("WScript.Shell").CurrentDirectory
Set objFSO  = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Path & "\Testing.txt", 8, True)    
objFile.WriteLine Path
objFile.close

VBScript是否可以保存包含中文字符的文件路径?

4

1 回答 1

1

该方法openTextFile有另一个可选参数 - format。它的值默认为 0,它以 ASCII 格式打开文件。要保存文件中的中文字符,可以通过指定参数的值以 UNICODE 格式打开文件format = -1。这是参考

objFso.openTextFile(path,8, true, -1)             '-1 = TriStateTrue = Opens the file as Unicode
path = split(wscript.scriptFullName, wscript.scriptname)(0) & "Testing.txt"
set objFso = createObject("scripting.filesystemobject")
set objFile = objFso.openTextFile(path,8, true, -1)
objFile.write path
objFile.Close
set objFile = Nothing
set objFso = Nothing
于 2019-02-05T06:53:35.587 回答