找回密码
 加入
搜索
查看: 2768|回复: 7

[AU3基础] 求助:_FileListToArray这个函数能不能设置搜索几层目录呢

  [复制链接]
发表于 2010-12-21 13:27:00 | 显示全部楼层 |阅读模式
比如说
#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[0]
                        Findfile($Path & '\' & $aFileList[$i])
                        GUICtrlSetData($List1, $Path & $aFileList[$i])
                Next
        EndIf
EndFunc   ;==>Findfile
 楼主| 发表于 2010-12-21 14:21:08 | 显示全部楼层
先谢谢版主。不过这个代码好像不行,我测试了一下。会搜索所选目录中的所有文件夹
发表于 2010-12-21 14:26:10 | 显示全部楼层
本帖最后由 水木子 于 2010-12-21 14:30 编辑

例子只是发给你点思路,还望你能从中理解到XXX!
既然N层都能搜索,何况两层呢!
 楼主| 发表于 2010-12-21 14:28:46 | 显示全部楼层
哈哈哈。明白。谢谢版主了
发表于 2010-12-22 08:32:29 | 显示全部楼层
个人感觉_FileListToArray($sPath[, $sFilter = "*"[, $iFlag = 0]])这个函数比用普通的文件递归方式速度快多了。
发表于 2010-12-22 09:28:53 | 显示全部楼层
回复 1# awfymwvf
以前写过一个搜索指定目录层数的东东。
传送门:http://www.autoitx.com/thread-16645-1-1.html
 楼主| 发表于 2010-12-22 09:56:55 | 显示全部楼层
谢谢楼上。马上研究一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 04:37 , Processed in 0.081955 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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