找回密码
 加入
搜索
查看: 1907|回复: 3

[AU3基础] 如何循环执行这段代码

[复制链接]
发表于 2015-12-10 17:14:01 | 显示全部楼层 |阅读模式
_filelist("c:")
Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*")

        While 1
                $file = FileFindNextFile($search)
                If @error Then                ;搜索完毕
                        FileClose($search)
                        Return
                ElseIf $file = "." Or $file = ".." Then                ;如果文件名是本目录或者上级目录
                        ContinueLoop
                ElseIf StringInStr(FileGetAttrib($searchdir & "" & $file), "D") Then                ;如果搜索到的是子目录
                        _filelist($searchdir & "" & $file)
                        ContinueLoop                ;不返回,下面会把".exe"结尾的目录也列进去
                EndIf
                If StringRight($file, 4) = ".jpg" Then                ;经过层层筛选,终于是找到文件了,匹配的写入列表文件

                                                 FileWriteLine(@ScriptDir&"\file.txt", $searchdir & "" & $file & @CRLF)
;                                                 FileCopy($searchdir & "" & $file,"f:\water")
                EndIf
        WEnd
EndFunc   ;==>_filelist
 楼主| 发表于 2015-12-10 17:47:09 | 显示全部楼层
help 求救。。
发表于 2015-12-10 18:14:03 | 显示全部楼层
如果循环執行的話,文檔會一直重複。
While 1
_filelist("c:")
WEnd
Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*")
;~ msgbox(0,"1","2")
        While 1
                $file = FileFindNextFile($search)
                If @error Then                ;搜索完?
                        FileClose($search)
                        Return
                ElseIf $file = "." Or $file = ".." Then                ;如果文件名是本目?或者上?目?
                        ContinueLoop
                ElseIf StringInStr(FileGetAttrib($searchdir & "" & $file), "D") Then                ;如果搜索到的是子目?
                        _filelist($searchdir & "" & $file)
                        ContinueLoop                ;不返回,下面?把".exe"?尾的目?也列?去
                EndIf
                If StringRight($file, 4) = ".jpg" Then                ;??????,?于是找到文件了,匹配的?入列表文件

                                                 FileWriteLine(@ScriptDir&"\file.txt", $searchdir & "" & $file & @CRLF)
;                                                 FileCopy($searchdir & "" & $file,"f:\water")
                EndIf
        WEnd
EndFunc   ;==>_filelist
 楼主| 发表于 2015-12-15 17:07:47 | 显示全部楼层
谢谢。遍历目录如何无限遍历。这个好像只能遍历二级目录
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-23 15:29 , Processed in 0.090418 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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