0

我有一个 VBScript,它在每 6 小时运行一次的 cfg 文件中用另一个时区替换时区。替换工作非常好,除了一个问题,每次运行脚本时 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 将 UTC-2 更改为可以正常工作的其他内容,尽管每次运行时,VBScript 都会删除顶行,因此在 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

提前致谢!问候,汤姆。

4

1 回答 1

1

脚本的 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)
Loop
于 2013-05-13T11:04:26.060 回答