python vbscript_vbscript - Python到VBScript转换 - SO中文参考 - www.soinside.com

我需要帮助将Python脚本转换为VBScript。我试图将.cal文件作为二进制值文件加载并编辑文件中的特定值,但是不幸的是,我的环境仅支持VBScript。import argparse

parser = argparse.ArgumentParser(description='Sapix Cal File Sensitivity Adjustment')

parser.add_argument("-calfile", default="test.cal", help="Enter the Calfile name (ex: 09781DK5081.cal")

parser.add_argument("-vtest", default=125, help="New Vtest setting (85-205)")

parser.add_argument("-vref", default=250, help="New Vref setting (250-120)")

args = parser.parse_args()

calfile = args.calfile

vtest = args.vtest

vref = args.vref

print(calfile)

print(vtest)

print(vref)

with open(calfile, "rb") as binary_file:

# Read the whole file at once

data = bytearray(binary_file.read())

# Find Line with VTEST setting

ivteststart = data.find(bytearray('PARALLEL_VOLTAGE_TEST', 'utf-8'))

ivtestend = data.find(b'\n',ivteststart)

# Remove original VTEST line

del data[ivteststart:ivtestend+1]

# Insert New Line with new VTEST

new_vtest = bytearray("PARALLEL_VOLTAGE_TEST %s\n" % (vtest),'utf-8')

data[ivteststart:ivteststart] = new_vtest

# Find Line with VREF setting

ivrefstart = data.find(bytearray('PARALLEL_VOLTAGE_REF', 'utf-8'))

ivrefend = data.find(b'\n',ivrefstart)

# Remove original VREF line

del data[ivrefstart:ivrefend+1]

# Insert New Line with new VREF

new_vref = bytearray("PARALLEL_VOLTAGE_REF %s\n" % (vref),'utf-8')

data[ivrefstart:ivrefstart] = new_vref

# Write new sensitivity settings to cal file

with open(calfile, "wb") as binary_file:

binary_file.write(data)

如果我将文件加载为文本文件,则能够进行更改,但是我不知道如何加载与二进制值相同的内容并进行更改Option Explicit

Dim objFso, objFolder, objFile, objOtF, cd, content

Dim targetDir

targetDir = "C:\Kiosk\UI"

Dim objRegExp

Set objRegExp = New RegExp

objRegExp.Pattern = "\bPARALLEL_VOLTAGE_TEST \d+\b"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(targetDir)

For Each objFile in objFolder.Files

If LCase(Right(objFile.Name, 4)) = ".cal" Then

cd = objFile.Name

Set objOtF = objFso.OpenTextFile(cd, 1)

content = objOtF.ReadAll

objOtF.Close

Set objOtF = objFso.OpenTextFile(cd, 2)

objOtF.Write objRegExp.Replace(content, "PARALLEL_VOLTAGE_TEST 230")

objOtF.Close

Dim objRegExp1

Set objRegExp1 = New RegExp

objRegExp1.Pattern = "\bPARALLEL_VOLTAGE_REF \d+\b"

Set objOtF = objFso.OpenTextFile(cd, 1)

content = objOtF.ReadAll

objOtF.Close

Set objOtF = objFso.OpenTextFile(cd, 2)

objOtF.Write objRegExp1.Replace(content, "PARALLEL_VOLTAGE_REF 190")

objOtF.Close

End If

Next

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值