0
我有一個VBScript,用每隔6小時運行一次的cfg文件中的另一個替換一個時區。除了一個問題,替換工作完全正常,VBScript每次運行腳本時都會刪除頂部行。 CFG文件看起來是這樣的:VBScript刪除行
//
// 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
提前感謝!問候,湯姆。
哦,我明白了!這工作就像一個魅力!謝謝! – Svenskunganka 2013-05-13 11:07:55