Filewriteline中怎么才能使用变量?
我有一个文件drvback.inf,其内容为c:\windows\inf\net1394.inf
c:\windows\inf\oem3.inf
C:\WINDOWS\system32\drivers\agrsm.sys
C:\WINDOWS\system32\agrsmsvc.exe
C:\WINDOWS\agrsmdel.exe
C:\WINDOWS\system32\agrscoin.dll
c:\windows\inf\oem0.inf
我用StringReplace函数把它变成drvback.bak,其内容为
windows\inf\net1394.inf
windows\inf\oem3.inf
WINDOWS\system32\drivers\agrsm.sys
WINDOWS\system32\agrsmsvc.exe
WINDOWS\agrsmdel.exe
WINDOWS\system32\agrscoin.dll
windows\inf\oem0.inf
我怎样才能将它变drvbackup.bat,其内容为
echo f| xcopy /s /e /f /h c:\windows\inf\net1394.infd:\DRVBACKUP\windows\inf\net1394.inf
echo f| xcopy /s /e /f /h c:\windows\inf\oem3.infd:\DRVBACKUP\windows\inf\oem3.inf
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\drivers\agrsm.sysd:\DRVBACKUP\WINDOWS\system32\drivers\agrsm.sys
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\agrsmsvc.exeD:\DRVBACKUP\WINDOWS\system32\agrsmsvc.exe
echo f| xcopy /s /e /f /h c:\WINDOWS\agrsmdel.exeD:\DRVBACKUP\WINDOWS\agrsmdel.exe
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\agrscoin.dllD:\DRVBACKUP\WINDOWS\WINDOWS\system32\agrscoin.dll
echo f| xcopy /s /e /f /h c:\windows\inf\oem0.infD:\DRVBACKUP\windows\inf\oem0.inf
用Filewriteline怎么实现?
$bak1=FileOpen("c:\drvback.bak", 0)
While 1
$line1 = FileReadLine($bak1)
If @error = -1 Then ExitLoop
$bat = FileOpen("c:\drvbackup.bat", 9)
FileWriteLine($bat, “echo f|xcopy /s /e /f /h c:\&$lin1 d:\DRVBACKUP\&$lin1”)
Wend
FileClose($bak1)
FileClose($bat)
Filewriteline那一句应该怎么使用????????望高手指教,本人不胜感激!!! FileWriteLine($bat, "echo f|xcopy /s /e /f /h c:\" & $lin1 & "d:\DRVBACKUP\" & "$lin1") ??? drvback.inf
c:\windows\inf\net1394.inf
c:\windows\inf\oem3.inf
C:\WINDOWS\system32\drivers\agrsm.sys
C:\WINDOWS\system32\agrsmsvc.exe
C:\WINDOWS\agrsmdel.exe
C:\WINDOWS\system32\agrscoin.dll
c:\windows\inf\oem0.inf
解决代码:
#include <file.au3>
Dim $inf
_FileReadToArray("drvback.inf",$inf)
For $x = 1 to $inf
FileWriteLine(FileOpen("drvbackup.bat", 1), "echo f| xcopy /s /e /f /h "&$inf[$x]&"d:\DRVBACKUP\"&StringTrimLeft($inf[$x], 3))
Next
建议:用数组读入和字符控制,代码会简洁些 本帖最后由 afan 于 2010-7-11 21:05 编辑
LZ考虑下用正则吧,没有这么多繁琐的步骤,替换可以一行代码搞定。
StringRegExpReplace($Str, '(\w\:\\(.+?))\h*(\r\n|$)', 'echo f\| xcopy \/s \/e \/f \/h "$1" "d\:\\DRVBACKUP\\$2"$3') 本帖最后由 afan 于 2010-7-11 21:00 编辑
Local $Str = _
'c:\windows\inf\net1394.inf ' & @CRLF & _
'c:\windows\inf\oem3.inf ' & @CRLF & _
'C:\WINDOWS\system32\drivers\agrsm.sys ' & @CRLF & _
'C:\WINDOWS\system32\agrsmsvc.exe ' & @CRLF & _
'C:\WINDOWS\agrsmdel.exe ' & @CRLF & _
'C:\WINDOWS\system32\agrscoin.dll ' & @CRLF & _
'c:\windows\inf\oem0.inf '
$Str = StringRegExpReplace($Str, '(\w\:\\(.+?))\h*(\r\n|$)', 'echo f\| xcopy \/s \/e \/f \/h "$1" "d\:\\DRVBACKUP\\$2"$3') ;一行即可,还补充了引号
MsgBox(0, '正则替换', $Str)
;实际应用为以下代码
;Local $Str = StringRegExpReplace(FileRead('drvback.inf'), '(\w\:\\(.+?))\h*(\r\n|$)', 'echo f\| xcopy \/s \/e \/f \/h "$1" "d\:\\DRVBACKUP\\$2"$3')
;FileWrite('drvbackup.bat', $Str) 谢谢楼上的朋友!!! 谢谢楼上的,我用以下代码实现了。
$inf = FileOpen("c:\drvbak.inf", 0)
While 1
$line = FileReadLine($inf)
If @error = -1 Then ExitLoop
;MsgBox(0, "读取的行:", $line)
$bat = FileOpen("c:\drvbak.bat", 9)
FileWriteLine($bat, "echo f|xcopy /s /e /f /h /y" & $line & " d:\DRVBACK\" &StringReplace($line,"c:\",""))
Wend
FileClose($bat)
FileClose($inf)
页:
[1]