找回密码
 加入
搜索
查看: 9060|回复: 22

[AU3基础] 请教,类似于此功能应该如何写呢?

 火.. [复制链接]
发表于 2011-5-13 18:21:45 | 显示全部楼层 |阅读模式

就是这样,启动时自动搜索硬盘上3层文件夹内的所有GHO文件,并且将搜索结果放在下拉列表中,便于快速选取。
可能较为麻烦,诚请教如何实现,谢谢。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-5-13 18:35:58 | 显示全部楼层
#include <file.au3>
Local $arr, $num, $str
Local $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[0]
        _filelist($Drive[$i])
Next
MsgBox(0, 0, $str)

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
发表于 2011-5-14 04:08:18 | 显示全部楼层
回复 2# 3mile
StringInStr($file, '.gho')
光这样是不行的,最简单的,比如*.gho.bk
发表于 2011-5-14 10:28:13 | 显示全部楼层
改成StringRight($file,4)='.gho'
发表于 2011-5-14 10:29:44 | 显示全部楼层
谢谢三笑牌代码
发表于 2011-5-14 10:57:26 | 显示全部楼层
回复 5# 3mile


    三笑太可爱了
发表于 2011-5-14 17:32:00 | 显示全部楼层
3mile不是"3英里"吗??
smile才是笑吧??
 楼主| 发表于 2011-5-14 18:24:18 | 显示全部楼层
本帖最后由 木头人 于 2011-5-14 18:27 编辑

回复 2# 3mile


    非常 感谢,看是看懂了,但是不知道怎么整合到我的程序的输入框中。我的代码如下
Func _SetMYJX()
        Local $noide, $nousb, $no1394, $rb, $hfp, $hfpf1, $arr, $num, $str, $chen
        $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, $str)
        $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[0]
                        $hfp3 = $var2[$i] & "|"
                        $hfp = $hfp & $hfp3
                        $hfp1 = $var2[1]
                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[0]
                                        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
请问如何将搜索出的镜像文件列表在
        $filelj = GUICtrlCreateCombo("请输入或选择镜像文件", 24, 51, 217, 21)
        GUICtrlSetData(-1, $str)
这个输入框中呢?没整明白,本人太菜不好意思,呵呵
GUICtrlCreateCombo框是一个组合框,可以使用“打开”按钮直接浏览并打开硬盘上的镜像。
也想实现程序打开后,自动将硬盘上存在的镜像列表在下拉框中,方便直接选取。
 楼主| 发表于 2011-5-15 01:51:15 | 显示全部楼层
为何大大们发的代码都有带解释连接,和颜色,我发的没有呢?
 楼主| 发表于 2011-5-15 01:51:21 | 显示全部楼层
为何大大们发的代码都有带解释连接,和颜色,我发的没有呢?
发表于 2011-5-15 03:22:07 | 显示全部楼层
本帖最后由 netegg 于 2011-5-15 03:43 编辑

回复 9# 木头人
不是很清楚你的目的到底是什么
3mile那个代码明白吧,你把
If StringInStr($file, '.gho') Then $str &= $searchdir & "\" & $file & 改成
If StringInStr($file, '.gho') Then $str &= $searchdir & "\" & $file & '|'
创建comdo的时候,GUICtrlSetData(-1, stringtrimright($str, 1) ,'')

评分

参与人数 1金钱 +20 收起 理由
木头人 + 20 谢谢

查看全部评分

发表于 2011-5-15 08:23:31 | 显示全部楼层
在我看起来挺复杂的。
 楼主| 发表于 2011-5-15 19:12:13 | 显示全部楼层
回复 12# netegg

谢谢蛋蛋回复,但是能告诉我怎么整合进我的程序里吗?谢谢
发表于 2011-5-15 19:59:25 | 显示全部楼层
整合什么,3mile不是给你写了个完整的吗
发表于 2011-5-15 20:48:15 | 显示全部楼层
不再使用全局变量,方便函数调用.
但因为有ByRef,所有要事先定义返回的变量,以及搜索的层数(默认搜索2层).
这样可以很方便的植入木头人兄的代码中了.
#include <file.au3>
#include <array.au3>

$abc = _Runsearchdir()
_ArrayDisplay($abc)

Func _Runsearchdir()
        Local $Array[1];提前定义返回数据的变量.
        Local $chen = 2;搜索的层数
        $Drive = DriveGetDrive("FIXED")
        For $i = 1 To $Drive[0]
                _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[UBound($str) + 1]
                        $str[UBound($str) - 1] = $searchdir & "\" & $file & @CRLF
                        $str[0] = UBound($str) - 1
                EndIf
        WEnd
EndFunc

评分

参与人数 1金钱 +20 收起 理由
木头人 + 20 加分表示感谢。

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-20 09:26 , Processed in 0.107104 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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