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

[AU3基础] [已解决]怎么返回一个目录里所有的文件名?

  [复制链接]
发表于 2016-2-5 01:31:59 | 显示全部楼层 |阅读模式
本帖最后由 3370225 于 2016-2-14 17:46 编辑

怎么返回一个目录里所有的文件名? 如题
发表于 2016-2-5 23:50:12 | 显示全部楼层
看帮助文档“FileFindFirstFile ”下面的第二个例子,或者UDF函数中的_FileReadToArray函数。这样的问题,论坛里面搜一下应该能找到很多。
发表于 2016-2-7 14:16:14 | 显示全部楼层
本帖最后由 king8462 于 2016-2-7 14:19 编辑

这是论坛中抄的循环递归代码,你自己改改。
Func Search($current)

     Local $search = FileFindFirstFile($current & "\*.*")

     While 1

               Dim $file = FileFindNextFile($search)

               If @error Or StringLen($file) < 1 Then ExitLoop

               If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then

                      shellexecute($current & "\" & $file)

                      Search($current & "\" & $file)

               else

                      filecopy($current & "\" & $file, @desktopdir  & "\" & $file)

                 EndIf

     WEnd

Return

EndFunc ;==>Search
发表于 2016-2-8 14:49:20 | 显示全部楼层
回复 1# 3370225


    $sDir = FindAllFile("d:")
Func FindAllFile($sDir)
    Local $hSearch = FileFindFirstFile($sDir & "\*.*")
   If $hSearch = -1 Then Return
    While 1
        Local $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        
        If @extended Then
            FindAllFile($sDir & "\" & $sFile)
            ContinueLoop
        EndIf
        FileWriteLine("找到的文件.txt",$sDir &"\" & $sFile)
     WEnd
        FileClose($hSearch)
EndFunc
发表于 2016-2-10 20:53:49 | 显示全部楼层
本帖最后由 nivisde 于 2016-2-10 20:59 编辑
#include <Array.au3>
Local $FILE_ARRAY[1]=[1] ;声明一维数组用来存放文件名
Local $FILE_ARRAY_INDEX=0
Local $FILE_NAME
Local $SHEARCH=FileFindFirstFile("C:\WINDOWS\system32\*.*") ; *.* 标识 查找 C:\WINDOWS\system32 下所有文件  如果需要查找其他后缀,可以改改例如 *.exe
If $SHEARCH<>-1 Then
        While 1
                $FILE_NAME = FileFindNextFile($SHEARCH)
                If @error Then ExitLoop
                ReDim $FILE_ARRAY[$FILE_ARRAY_INDEX+1] ;把数组扩大下标,用于存放找到的文件名
                $FILE_NAME=StringSplit($FILE_NAME,".") ;去掉文件后缀
                $FILE_ARRAY[$FILE_ARRAY_INDEX]=$FILE_NAME[1] ;装入数组
                $FILE_ARRAY_INDEX+=1
        WEnd
        FileClose($SHEARCH)
EndIf
_ArrayDisplay($FILE_ARRAY) ;打印观察
发表于 2016-2-11 21:31:57 | 显示全部楼层
没看明白啊。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 02:11 , Processed in 0.076473 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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