程式實現的是系統內容變數設定,更改Enviroment為user可設定使用者變數。
Dim currentpathcurrentpath=createobject("Scripting.FileSystemObject").GetFolder(".").PathMsgBox currentpathDim ocrpathocrpath=currentpath&"\Tesseract-OCR"SetTheEnv(ocrpath)Function SetTheEnv(ocrpath)Dim pSysEnvSet pSysEnv = CreateObject("WScript.Shell").Environment("System") pSysEnv("TESSDATA_PREFIX")=ocrpath&"\"Dim ExistValueExistValue=pSysEnv("path")Dim target,s,exist,appendvalueexist=Falseappendvalue=ocrpath&";"&ocrpath&"\training"ExistValue=ExistValue&";"&appendvalueExistValue=reduce(ExistValue,False,";")target=split(ExistValue,";")ExistValue=""For Each s In targetIf s<>"" ThenExistValue=ExistValue&s&";"End IfNextpSysEnv("path")=ExistValue'ExistValue=pSysEnv("wdir")'MsgBox("WDIR="&ExistValue)MsgBox "環境設定成功!"End FunctionFunction reduce(srcstr,casesentive,sp)Dim objDict,x,ysrcarr=split(Trim(srcstr),sp)Set objDict=createobject("Scripting.Dictionary")For Each x In srcArrIf Not casesentive Then y=LCase(x)Elsey=xEnd IfIf Not objDict.Exists(y) Then If y<>lcase(driverLetter)&"\" ThenobjDict.Add y,xEnd IfEnd IfNextreduce=Join(objDict.Items,sp)Set objDict=NothingEnd Function