不能通过VBScript将汉字保存在文本文件中。
VBScript位于一个中文名称为VIEW的文件夹中。该脚本将创建一个文本文件,其中将显示当前工作目录。汉字不能保存在文件中。 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是否可以保存包含汉字的文件路径?
答案 0 :(得分:1)
方法openTextFile
具有另一个可选参数-format
。默认情况下,其值为0,这将以ASCII格式打开文件。要将中文字符保存在文件中,可以通过指定参数format = -1
的值以UNICODE格式打开文件。这是 Reference 。
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