我有一个用cfg文件中的时区替换另一个时区的VBScript,该文件每6小时运行一次。替换后的代码运行得很好,除了一个问题,每次我运行脚本时,VBScript都会删除第一行。cfg文件如下所示:
//
// config.cfg
//
// comments are written with "//" in front of them.
// GLOBAL SETTINGS
hostname = "Blablabla (v1.7.6.1/Build 103718) [REGULAR|3DP:ON|CH:ON][UTC-2] - SomeMoreCharactersAndText虽然每次运行时,VBScript都会删除顶行,但VBScript会将UTC-2更改为其他正常运行的代码,因此在运行3次后看起来如下所示:
// comments are written with "//" in front of them.
// GLOBAL SETTINGS
hostname = "Blablabla (v1.7.6.1/Build 103718) [REGULAR|3DP:ON|CH:ON][UTC-2] - SomeMoreCharactersAndText在运行六次之后,它将删除主机名行本身。我想知道VBScript代码是不是有什么问题?我从一个批处理文件执行VBScript,该批处理文件如下所示:
@echo off
echo Setting Current Timezone...
cd "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO\dayz_1.chernarus"
rename config_XXXXXX.cfg config_XXXXXX_old.cfg
cscript /nologo myreplace.vbs > newfile
ren newfile config_XXXXXX.cfg
del config_XXXXXX_old.cfg这是VBScript本身:
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "C:\Program Files (x86)\Steam\SteamApps\common\Arma 2 CO\dayz_1.chernarus\config_XXXXXX_old.cfg"
Set objFile = objFS.OpenTextFile(strFile)
strLine = objFile.ReadLine
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"UTC-8")> 0 Then
strLine = Replace(strLine,"UTC-8","UTC+10")
ElseIf InStr(strLine,"UTC+10")> 0 Then
strLine = Replace(strLine,"UTC+10","UTC+4")
ElseIf InStr(strLine,"UTC+4")> 0 Then
strLine = Replace(strLine,"UTC+4","UTC-2")
ElseIf InStr(strLine,"UTC-2")> 0 Then
strLine = Replace(strLine,"UTC-2","UTC-8")
End If
WScript.Echo strLine
Loop
objFile.Close提前感谢!你好,汤姆。
发布于 2013-05-13 19:04:26
脚本的IO部分的结构:
strLine = objFile.ReadLine (a)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine (b)
...
WScript.Echo strLine (c)
Loop显示第一行(a)没有回显,而后面的所有行(b)都回显。
尝试:
strLine = objFile.ReadLine (a)
WScript.Echo strLine (c)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine (b)
...
WScript.Echo strLine (c)
Loophttps://stackoverflow.com/questions/16520453
复制相似问题