本帖最后由 infotechewen 于 2011-5-25 21:45 编辑
功能:定时备份指定目录下(包括子文件夹)所有*.xls 文件,到指定备份目录下,并跟源路径一致。
MsgBox(262144,"**********","框框是难看了点,不过咋说也是个脚本,对不?" & @CRLF & "熟练者可直接修改setup.ini文件,无需运行此设置" , 5)
$sDir = InputBox("备份源路径" ,"你想备份什么目录(切记以\结束!)" & @CRLF & "格式 g:\, g:\files\" , "g:\files\")
If @error = 1 Then Exit
IniWrite(@ScriptDir&"\setup.ini","backup", "源路径" ,$sDir)
$sFile = InputBox("备份文件格式", "你想备份该目录下什么格式的文件(支持通配符)" & @CRLF & "格式 *.xls , *.xls?" , "*.xls?")
If @error = 1 Then Exit
IniWrite(@ScriptDir&"\setup.ini","backup" , "文件格式" ,$sFile)
$copydir = InputBox("备份目的路径" ,"你想备份到哪?(切记以\结束!)" & @CRLF & "格式 e:\, e:\backup\" , "e:\backup\")
If @error = 1 Then Exit
IniWrite(@ScriptDir&"\setup.ini","backup", "目的路径" ,$copydir)
$hour = InputBox("备份时间设置","请输入开始备份时间(24小时制)" & @CRLF &"例:2330 23点30分" , "2330" )
If @error = 1 Then Exit
IniWrite(@ScriptDir&"\setup.ini","backup" , "备份时间" ,$hour) ;时间格式 在每天凌晨2点半启动: 0230
Dim $flag = MsgBox(4,"完成","设置完成。是否现在启动备份计划?")
If $flag = 7 Then Exit
If ProcessExists("backup.exe") Then ProcessClose("backup.exe")
Run(@ScriptDir&"\backup.exe")
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=..\..\AU3\FB.ico
#AutoIt3Wrapper_Res_Comment=每天定时备份文件
#AutoIt3Wrapper_Res_Fileversion=1.0.0.1
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <file.au3>
Opt("TrayIconHide",1)
RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "2330AutoBackup", "REG_SZ", @ScriptFullPath)
$sDir = IniRead(@ScriptDir & "\setup.ini" , "backup" ,"源路径" ,"error")
$sFile = IniRead(@ScriptDir & "\setup.ini" , "backup" ,"文件格式" ,"error")
$copydir = IniRead(@ScriptDir & "\setup.ini" , "backup" ,"目的路径" ,"error")
$hour = IniRead(@ScriptDir & "\setup.ini" , "backup" ,"备份时间" ,"error") & "01"
$sOutFile = @TempDir & "\files.txt"
$logpath = @ScriptDir & "\log\"
While 1
Sleep(1000)
If @HOUR & @MIN & @SEC = $hour Then
RunWait(@COMSPEC & ' /c dir /a /s /b "' & $sDir & $sFile & '" > "' & $sOutFile & '"' , "", @SW_HIDE)
For $n = 1 To 1000
$read = FileReadLine($sOutFile , $n)
If @error = -1 Then ExitLoop
$t = StringLeft($sDir ,2)
$dDir = StringReplace($read,$t, "")
$copy = String($read)
FileCopy($read , $copydir & @YEAR & @MON & @MDAY & $dDir ,9)
_FileWriteLog($logpath & @YEAR & @MON & @MDAY & ".log" , "成功备份 " & $copy & " 到 " & $copydir & @YEAR & @MON & @MDAY & $dDir)
Next
FileDelete($sOutFile)
EndIf
WEnd
写了个每天定时备份文件的代码。但感觉用filereadline的话,如果该目录下文件太多,可能会比较耗资源。fileread的话速度快很多,但用fileread读出来的一堆文件路径,用filecopy调用时不成功,或不知道办法。请教:
1,这个例子中,用fileread的话如何写?(读出的貌似出来array?)
2,提高效率,简洁代码。用其他更好的办法达到同样的功能。
谢谢。 |