找回密码
 加入
搜索
查看: 3033|回复: 6

[AU3基础] Filewriteline中怎么才能使用变量?

  [复制链接]
发表于 2010-7-11 11:16:48 | 显示全部楼层 |阅读模式
我有一个文件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.inf  d:\DRVBACKUP\windows\inf\net1394.inf
echo f| xcopy /s /e /f /h c:\windows\inf\oem3.inf  d:\DRVBACKUP\windows\inf\oem3.inf
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\drivers\agrsm.sys  d:\DRVBACKUP\WINDOWS\system32\drivers\agrsm.sys
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\agrsmsvc.exe  D:\DRVBACKUP\WINDOWS\system32\agrsmsvc.exe
echo f| xcopy /s /e /f /h c:\WINDOWS\agrsmdel.exe  D:\DRVBACKUP\WINDOWS\agrsmdel.exe
echo f| xcopy /s /e /f /h c:\WINDOWS\system32\agrscoin.dll  D:\DRVBACKUP\WINDOWS\WINDOWS\system32\agrscoin.dll
echo f| xcopy /s /e /f /h c:\windows\inf\oem0.inf  D:\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那一句应该怎么使用????????望高手指教,本人不胜感激!!!
发表于 2010-7-11 13:34:43 | 显示全部楼层
FileWriteLine($bat, "echo f|xcopy /s /e /f /h c:\" & $lin1 & "d:\DRVBACKUP\" & "$lin1") ???
发表于 2010-7-11 17:47:15 | 显示全部楼层
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[0]
FileWriteLine(FileOpen("drvbackup.bat", 1), "echo f| xcopy /s /e /f /h "&$inf[$x]&"  d:\DRVBACKUP"&StringTrimLeft($inf[$x], 3))
Next

建议:用数组读入和字符控制,代码会简洁些

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2010-7-11 20:22:40 | 显示全部楼层
本帖最后由 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')
发表于 2010-7-11 20:55:41 | 显示全部楼层
本帖最后由 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)

评分

参与人数 1金钱 +11 收起 理由
lynfr8 + 11

查看全部评分

 楼主| 发表于 2010-7-17 20:31:22 | 显示全部楼层
谢谢楼上的朋友!!!
 楼主| 发表于 2010-7-17 20:54:39 | 显示全部楼层
谢谢楼上的,我用以下代码实现了。
$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)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 01:37 , Processed in 0.077311 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表