亲爱的3mile
看了您的代码受益很深,只是
一些版本果真会搜出.或者..来吗? 回复 16# 502762378
.和..好像对现在的单机系统倒确实没太大必要,但是为了保险起见,加上没坏处 回复 15# 3mile Func _SetMYJX()
Local $noide, $nousb, $no1394, $rb, $hfp, $hfpf1, $arr, $num, $str, $chen
$abc = _Runsearchdir()
_Runsearchdir()
$MForm1 = GUICreate("还原镜像", 322, 315, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_BORDER), 0, $XForm1)
$MGroup1 = GUICtrlCreateGroup("镜像", 8, 8, 305, 153)
$filelj = GUICtrlCreateCombo("请输入或选择镜像文件", 24, 51, 217, 21)
GUICtrlSetData(-1, $abc)
$MButton1 = GUICtrlCreateButton("打 开", 248, 51, 51, 21)
GUICtrlCreateLabel("请点击 <打开> 镜像文件:", 24, 32, 200, 17)
GUICtrlCreateLabel("镜像恢复到分区:", 24, 84, 100, 17)
$var2 = DriveGetDrive("FIXED")
If Not @error Then
For $i = 1 To $var2
$hfp3 = $var2[$i] & "|"
$hfp = $hfp & $hfp3
$hfp1 = $var2
Next
EndIf
$MCombo1 = GUICtrlCreateCombo("", 128, 80, 113, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $CBS_UPPERCASE))
GUICtrlSetData(-1, $hfp, $hfp1)
$MButton2 = GUICtrlCreateButton("还原", 62, 283, 75, 25)
$MButton3 = GUICtrlCreateButton("关闭", 190, 283, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $MButton3
GUIDelete($MForm1)
Return 0
Case $MButton1
$drivedbs = ""
$jxfile = FileOpenDialog("选择镜像文件", "d:\", "(*.gho;*.ghs)|所有文件(*.*)", 1 + 2, "", $XForm1)
If Not @error Then
FileDelete(@ScriptDir & "\ghostr.bat")
$PFPD = StringUpper(StringLeft($jxfile, 3))
If DriveGetType($PFPD) <> "Fixed" Then
MsgBox(4096, "错误", "只支持硬盘恢复。")
GUICtrlSetData($filelj, "", "")
ContinueLoop
EndIf
GUICtrlSetData($filelj, $jxfile, "")
EndIf
Case $MButton2
$jxfile = GUICtrlRead($filelj)
FileDelete(@ScriptDir & "\ghostr.bat")
$PFPD = StringUpper(StringLeft($jxfile, 3))
If DriveGetType($PFPD) <> "Fixed" Then
MsgBox(4096, "错误", "目前只支持硬盘恢复。
ContinueLoop
EndIf
GUICtrlSetData($filelj, $jxfile, "")
$hfpf = GUICtrlRead($MCombo1) & "\"
$pd1 = 1
$pd2 = 1
$drivedb = StringSplit(StringUpper($disbk), "|")
For $i = 1 To $drivedb
If $pd1 = 1 Then
If $drivedb[$i] = $PFPD Then
$drivedbs = $drivedb[$i + 1]
$pd1 = 0
EndIf
EndIf
If $pd2 = 1 Then
If $drivedb[$i] = $hfpf Then
$hfpf1 = $drivedb[$i + 1]
$pd2 = 0
EndIf
EndIf
If $pd1 = 0 And $pd2 = 0 Then ExitLoop
Next
If $drivedbs = $hfpf1 Then
MsgBox(16 + 4096, "错误", "备份文件与恢复盘不能是同一分区。", 0, $MForm1)
ContinueLoop
EndIf
FileWrite(@ScriptDir & "\ghostr.bat", "ghost -clone,mode=pload,src=" & $drivedbs & StringTrimLeft($jxfile, 2) & ":1,dst=" & $hfpf1 & " -sure")
_SetQJ()
Shutdown(6)
EndSwitch
WEnd
EndFunc ;==>_SetMYJX
Func _Runsearchdir()
Local $Array;提前定义返回数据的变量.
Local $chen = 2;搜索的层数
$Drive = DriveGetDrive("FIXED")
For $i = 1 To $Drive
_filelist($Drive[$i], $Array, $chen)
Next
Return $Array
EndFunc
Func _filelist($searchdir, ByRef $str, $chen = 2)
$search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
While 1
$file = FileFindNextFile($search) ;;;查找下一个文件
If @error Then ;;;如果找不到文件
FileClose($search) ;;;则关闭此句柄
Return ;;;返回
ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
ContinueLoop ;;;在某些版本的AU3里面可以不需要上行和这行。
ElseIf StringInStr(FileGetAttrib($searchdir & "\" & $file), "D") Then;;如果找到的是一个文件夹,则
$arr = StringRegExp($searchdir & "\" & $file, '\\', 3)
$num = UBound($arr)
If $num < $chen Then
_filelist($searchdir & "\" & $file, $str, $chen) ;;递归调用filelist函数,并传参数"$searchdir & "\" & $file"
EndIf
EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
If StringRight($file, 4) = '.gho' Then
;~ $str &= $searchdir & "\" & $file & @CRLF;_ArrayAdd($filelist,$searchdir & "\" & $file );MsgBox( 0,0,$searchdir & "\" & $file & @crlf )
ReDim $str
$str = $searchdir & "\" & $file & @CRLF
$str = UBound($str) - 1
EndIf
WEnd
EndFunc不好意思,本人太菜,加入后,程序不能获的$abc 变量。。$abc 变量为空。
也尝试了使用探钮激活你给的代码,但是也是一样无法获得 $abc变量。。 回复 15# 3mile Func _SetMYJX()
Local $noide, $nousb, $no1394, $rb, $hfp, $hfpf1, $arr, $num, $str, $chen
$chen=IniRead("onekey.ini","data","search","2")
If @error Then
MsgBox(0,"警告","按默认只搜索2层目录")
$chen=2
EndIf
$Drive = DriveGetDrive("FIXED")
For $i = 1 To $Drive
_filelist($Drive[$i])
Next
$MForm1 = GUICreate("还原镜像", 322, 315, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_BORDER), 0, $XForm1)
$MGroup1 = GUICtrlCreateGroup("镜像", 8, 8, 305, 153)
$filelj = GUICtrlCreateCombo("搜索。", 24, 32, 217, 21)
GUICtrlSetData(-1, stringtrimright($str, 1) ,'')
$filelj = GUICtrlCreateInput("请输入或选择镜像文件", 24, 51, 217, 21)
$MButton1 = GUICtrlCreateButton("打 开", 248, 51, 51, 21)
GUICtrlCreateLabel("请点击 <打开> 镜像文件:", 24, 32, 200, 17)
GUICtrlCreateLabel("镜像恢复到分区:", 24, 84, 100, 17)
$var2 = DriveGetDrive("FIXED")
If Not @error Then
For $i = 1 To $var2
$hfp3 = $var2[$i] & "|"
$hfp = $hfp & $hfp3
$hfp1 = $var2
Next
EndIf
$MCombo1 = GUICtrlCreateCombo("", 128, 80, 113, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $CBS_UPPERCASE))
GUICtrlSetData(-1, $hfp, $hfp1)
$MButton2 = GUICtrlCreateButton("还原", 62, 283, 75, 25)
$MButton3 = GUICtrlCreateButton("关闭", 190, 283, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $MButton3
GUIDelete($MForm1)
Return 0
Case $MButton1
$drivedbs = ""
$jxfile = FileOpenDialog("选择镜像文件", "d:\", "(*.gho;*.ghs)|所有文件(*.*)", 1 + 2, "", $XForm1)
If Not @error Then
FileDelete(@ScriptDir & "\ghostr.bat")
$PFPD = StringUpper(StringLeft($jxfile, 3))
If DriveGetType($PFPD) <> "Fixed" Then
MsgBox(4096, "错误", "只支持硬盘恢复。")
GUICtrlSetData($filelj, "", "")
ContinueLoop
EndIf
GUICtrlSetData($filelj, $jxfile, "")
EndIf
Case $MButton2
$jxfile = GUICtrlRead($filelj)
FileDelete(@ScriptDir & "\ghostr.bat")
$PFPD = StringUpper(StringLeft($jxfile, 3))
If DriveGetType($PFPD) <> "Fixed" Then
MsgBox(4096, "错误", "目前只支持硬盘恢复。
ContinueLoop
EndIf
GUICtrlSetData($filelj, $jxfile, "")
$hfpf = GUICtrlRead($MCombo1) & "\"
$pd1 = 1
$pd2 = 1
$drivedb = StringSplit(StringUpper($disbk), "|")
For $i = 1 To $drivedb
If $pd1 = 1 Then
If $drivedb[$i] = $PFPD Then
$drivedbs = $drivedb[$i + 1]
$pd1 = 0
EndIf
EndIf
If $pd2 = 1 Then
If $drivedb[$i] = $hfpf Then
$hfpf1 = $drivedb[$i + 1]
$pd2 = 0
EndIf
EndIf
If $pd1 = 0 And $pd2 = 0 Then ExitLoop
Next
If $drivedbs = $hfpf1 Then
MsgBox(16 + 4096, "错误", "备份文件与恢复盘不能是同一分区。", 0, $MForm1)
ContinueLoop
EndIf
FileWrite(@ScriptDir & "\ghostr.bat", "ghost -clone,mode=pload,src=" & $drivedbs & StringTrimLeft($jxfile, 2) & ":1,dst=" & $hfpf1 & " -sure")
_SetQJ()
Shutdown(6)
EndSwitch
WEnd
EndFunc ;==>_SetMYJX
Func _filelist($searchdir)
$search = FileFindFirstFile($searchdir & "\*.*") ;;;;查指定目录下的文件
If $search = -1 Then Return -1 ;;;;如果找不到,返回值 -1
While 1
$file = FileFindNextFile($search) ;;;查找下一个文件
If @error Then ;;;如果找不到文件
FileClose($search) ;;;则关闭此句柄
Return ;;;返回
ElseIf $file = "." Or $file = ".." Then ;;如果找到的文件名为.或..则ContinueLoop
ContinueLoop ;;;在某些版本的AU3里面可以不需要上行和这行。
ElseIf StringInStr(FileGetAttrib($searchdir & "\" & $file), "D") Then;;如果找到的是一个文件夹,则
$arr = StringRegExp($searchdir & "\" & $file, '\\', 3)
$num = UBound($arr)
If $num < $chen Then
_filelist($searchdir & "\" & $file) ;;递归调用filelist函数,并传参数"$searchdir & "\" & $file"
EndIf
EndIf ;;;$file为查找到的文件夹名称,上一行意思就是进入此文件夹继续查找文件.如此循环
If StringInStr($file, '.gho') Then $str &= $searchdir & "\" & $file & @CRLF;_ArrayAdd($filelist,$searchdir & "\" & $file );MsgBox( 0,0,$searchdir & "\" & $file & @crlf )
WEnd
EndFunc ;==>_filelist尝试这样写也不行。。 GUICtrlSetData(-1, $abc)
改为local $gho
for $i=1 to $abc
$gho&=$abc[$i]&"|"
Next
$gho=StringTrimRight($gho,1)
GUICtrlSetData(-1, $gho) 回复 20# 3mile
还是不行,3笑给个QQ,帮我看看代码行吗?非常感谢。
程序没有提示错误,但是还是获取不了镜像文件。 3mile的代码只能搜索到一层文件夹下,如果能无限搜索就OK了,研究一下 这个不错,~~~
页:
1
[2]