VBScript删除行

时间:2013-05-13 10:58:42

标签: windows batch-file vbscript

我有一个VBScript用cfg文件替换另一个时区,每隔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将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

提前致谢!此致,汤姆。

1 个答案:

答案 0 :(得分: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