求助,处理 unicode 格式文件
本帖最后由 yuanyannian 于 2014-8-10 09:26 编辑我是 AU3 外行初学,想处理 .INF 文件(一般都是 unicode 格式,个别是 ANSI 格式),请各位专家指点、修改如下代码,谢谢!Dim $Msg, $rFile, $iPath, $tPath, $sLoca
$Msg = "Example:HojoHE.exe -Sdefault -ID:\aaa -TE:\aaa\bbb -L00000409"
If $CmdLine=4 Then
If StringLeft($CmdLine,2)="-S" And StringLeft($CmdLine,2)="-I" And StringLeft($CmdLine,2)="-T" And StringLeft($CmdLine,2)="-L" Then
$rFile = StringMid($CmdLine,3)
$iPath = StringMid($CmdLine,3)
$tPath = StringMid($CmdLine,3)
$sLoca = StringMid($CmdLine,3)
Else
MsgBox(0,"Error", "Input Error"& @CRLF & @CRLF & $msg)
EndIf
ElseIf $CmdLine=3 Then
If StringLeft($CmdLine,2)="-S" And StringLeft($CmdLine,2)="-I" And StringLeft($CmdLine,2)="-T" Then
$rFile = StringMid($CmdLine,3)
$iPath = StringMid($CmdLine,3)
$tPath = StringMid($CmdLine,3)
Else
MsgBox(0,"Error", "Input Error"& @CRLF & @CRLF & $msg)
EndIf
ElseIf $CmdLine=1 Then
If ($CmdLine)="?" Then
MsgBox(0,"Exp", $Msg)
Else
MsgBox(0,"Error", "Input Error" & @CRLF & @CRLF & "Example:HojoHE.exe ?")
EndIf
Else
MsgBox(0,"Error", "Input Error" & @CRLF & @CRLF & $Msg)
EndIf
; 以下这段太罗嗦了,用vbs 可以数组解决,AU3 我就不会了。
If FileExists($tPath) = 0 Then DirCreate($tPath)
Dim $ss, $File
Select
Case $rFile = "default"
If FileExists($iPath & "\HIVEDEF.INF") Then FileCopy($iPath & "\HIVEDEF.INF", $tPath, 1)
$File = $tPath & "\HIVEDEF.INF"
FileProcess()
Case $rFile = "software"
If FileExists($iPath & "\HIVESFT.INF") Then
FileCopy($iPath & "\HIVESFT.INF", $tPath, 1)
$File = $tPath & "\HIVESFT.INF"
FileProcess()
EndIf
If FileExists($iPath & "\HIVECLS.INF") Then
FileCopy($iPath & "\HIVECLS.INF", $tPath, 1)
$File = $tPath & "\HIVECLS.INF"
FileProcess()
EndIf
If FileExists($iPath & "\HIVESXS.INF") Then
FileCopy($iPath & "\HIVESXS.INF", $tPath, 1)
$File = $tPath & "\HIVESXS.INF"
FileProcess()
EndIf
If FileExists($iPath & "\HIVSFT32.INF") Then
FileCopy($iPath & "\HIVSFT32.INF", $tPath, 1)
$File = $tPath & "\HIVSFT32.INF"
FileProcess()
EndIf
If FileExists($iPath & "\HIVCLS32.INF") Then
FileCopy($iPath & "\HIVCLS32.INF", $tPath, 1)
$File = $tPath & "\HIVCLS32.INF"
FileProcess()
EndIf
If FileExists($iPath & "\DMREG.INF") Then
FileCopy($iPath & "\DMREG.INF", $tPath, 1)
$File = $tPath & "\DMREG.INF"
FileProcess()
EndIf
Case $rFile = "setupreg.hiv"
If FileExists($iPath & "\HIVESYS.INF") Then FileCopy($iPath & "\HIVESYS.INF", $tPath, 1)
$File = $tPath & "\HIVESYS.INF"
FileProcess()
Case Else
MsgBox(0, "Error", "The parameter isn't supported!" & @CRLF & @CRLF & "Must be 'default', or 'software', or 'setupreg.hiv'.")
EndSelect
Func FileProcess()
MsgBox(0,"Error", $File)
;此处,如何判断相应文件,如果是ANSI格式,转换为 unicode 格式?
;此处,如何查找并替换相应文本中的字符串,如果存在就替换,不存在就忽略,并添加行?
;需要替换的内容:
;HKCU," 替换为 HKLM,"WB-default\ (HKCU, 后面可能有空格,如果存在就替换,否则忽略,下同)
;HKLM,"SYSTEM\ 为 HKLM,"WB-setup\
;HKLM,"SOFTWARE\ 为 HKLM,"WB-software\
;HKCR," 为 HKLM,"WB-software\Classes\
;HKCR,. 为 HKLM,WB-software\Classes\.
;添加 和其下面的 AddReg = AddReg 和 AddReg = AddReg.Upgarde 行
EndFunc 不知是我提的问题太幼稚,或是什么,很着急,却怎么不见热心的帮助? 怎么没有协助,AU3论坛? 本帖最后由 user3000 于 2014-8-11 21:09 编辑
回复 3# yuanyannian
判断文件编码格式: FileGetEncoding
转换ANSI ---> unicode:StringToBinary BinaryToString
用数组,简化的代码: Case $rFile = "software"
Local $aSoft = ['HIVESFT.INF', 'HIVECLS.INF', 'HIVESXS.INF', 'HIVSFT32.INF', 'HIVCLS32.INF', 'DMREG.INF']
For $i = 0 To UBound($aSoft) -1
Local $sFile = $iPath & '\' & $aSoft[$i]
If FileExists($sFile) Then
FileCopy($sFile, $tPath, 1)
$File = $tPath & '\' & $aSoft[$i]
FileProcess()
EndIf
Next 回复 4# user3000
感谢了。
另外,我想重点解决:文件处理后如何保持原有文件编码格式不变?比如处理前是 unicode ,处理过程及处理后仍然是 unicode 格式。现在这段代码,处理后会统一变成 ANSI 编码格式。
请求帮助! 为何总是没有高手帮助? 前来学习。。。。。。。。。。。。。。。。。。。 碰到和你一样的问题,试下看看能解决不~
页:
[1]