awfymwvf 发表于 2010-12-21 13:27:00

求助:_FileListToArray这个函数能不能设置搜索几层目录呢

比如说#Include <File.au3>
#Include <Array.au3>

$FileList=_FileListToArray("D:\","*.gho")
If @Error=1 Then
        MsgBox (0,"","No Folders Found.")
        Exit
EndIf
If @Error=4 Then
        MsgBox (0,"","No Files Found.")
        Exit
EndIf
_ArrayDisplay($FileList,"搜索")是搜索D盘所有目录吧,要是只想搜索两层子目录呢?如何实现呢?

水木子 发表于 2010-12-21 14:06:37

#include <File.au3>
#include <GuiListBox.au3>
#include <WindowsConstants.au3>

GUICreate("文件搜索", 380, 350)
$List1 = GUICtrlCreateList("", 5, 5, 370, 300)
$Input1 = GUICtrlCreateInput("", 5, 310, 300, 21)
$But1 = GUICtrlCreateButton("浏览", 305, 308, 70, 25, $WS_GROUP)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit
                Case $But1
                        $var = FileSelectFolder("选择一个文件夹.", "")
                        If @error <> 1 Then
                                GUICtrlSetData($Input1, $var)
                                If StringRight($var, 1) = '\' Then $var = StringLeft($var, StringLen($var) - 1)
                                _GUICtrlListBox_ResetContent($List1)
                                Findfile($var)
                        EndIf
        EndSwitch
WEnd

Func Findfile($Path)
        $aFileList = _FileListToArray($Path)
        If Not @error Then
                For $i = 1 To $aFileList
                        Findfile($Path & '\' & $aFileList[$i])
                        GUICtrlSetData($List1, $Path & $aFileList[$i])
                Next
        EndIf
EndFunc   ;==>Findfile

awfymwvf 发表于 2010-12-21 14:21:08

先谢谢版主。不过这个代码好像不行,我测试了一下。会搜索所选目录中的所有文件夹

水木子 发表于 2010-12-21 14:26:10

本帖最后由 水木子 于 2010-12-21 14:30 编辑

例子只是发给你点思路,还望你能从中理解到XXX!
既然N层都能搜索,何况两层呢!

awfymwvf 发表于 2010-12-21 14:28:46

哈哈哈。明白。谢谢版主了

ahphsautoit 发表于 2010-12-22 08:32:29

个人感觉_FileListToArray($sPath[, $sFilter = "*"[, $iFlag = 0]])这个函数比用普通的文件递归方式速度快多了。

3mile 发表于 2010-12-22 09:28:53

回复 1# awfymwvf
以前写过一个搜索指定目录层数的东东。
传送门:http://www.autoitx.com/thread-16645-1-1.html

awfymwvf 发表于 2010-12-22 09:56:55

谢谢楼上。马上研究一下
页: [1]
查看完整版本: 求助:_FileListToArray这个函数能不能设置搜索几层目录呢