FBWOLF 发表于 2008-7-30 16:54:52

求一个遍历目录然后将文件写入文本的源码!

希望有源码的大大分享!

      ................................................................答案在 6 楼和 8 楼 !

pcbar 发表于 2008-7-30 17:51:11

dir /s/b/e >a.txt
??

FBWOLF 发表于 2008-7-30 18:28:26

谢谢版主,可能你没有理解我的意思!
我要做到的是一个遍历目录,遇到文件夹就继续向下递归循环!然后将文件都写入一个文本中!
以前论坛有一位朋友曾经写过,让我不小心把UDF给丢了!

sanhen 发表于 2008-7-30 18:48:00

将文件写入一个文本中?不大理解。

大绯狼 发表于 2008-7-30 19:27:07

楼上的同志 文本和文本框是不一样的
我这里有这个UDF 本来想发出来的 但是这个破网吧把USB口给拔掉了我**

jhwl 发表于 2008-7-31 16:24:51

是不是这样的?
_filelist("D:\jhwl")
;=====================www.autoitx.com===========
;Author:jhwl
;$DirSource 搜索路径
Func _filelist($DirSource)

                If FileExists($DirSource) = 0 Then
                MsgBox(64, "提示", "【" & $DirSource & "】目录不存在!请重新指定有效目录.")
        Else
                Local $WorkingDir, $search, $file
                FileChangeDir($DirSource)
                $search = FileFindFirstFile("*.*")
                If $search = -1 Then
                        ;MsgBox(64, "完成提示", "在目录【" & $DirSource & "】下未找到任何文件和子目录!")
                Else
                        While 1
                                $file = FileFindNextFile($search)
                                If @error Then ExitLoop
                                If StringInStr(FileGetAttrib($DirSource & "\" & $file), "D") Then
                                        _filelist($DirSource & "\" & $file)
                                Else
                                        ;MsgBox(0, 000, $DirSource & "\" & $file)
                                        FileWriteLine(@ScriptDir&"\file.txt", $DirSource & "\" & $file & @CRLF)
                                EndIf
                        WEnd
                EndIf
        EndIf
EndFunc   

FBWOLF 发表于 2008-8-4 19:18:47

谢谢!给你加钱!

jhwl 发表于 2008-8-9 12:43:27

最近有点忙,才看到你的邮件
以下是遍历搜索*.exe文件
_filelist("D:\jhwl")
Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*.*")
        If $search = -1 Then Return -1
        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)
                EndIf
                If StringRight($file, 4) = ".exe" Then
                       FileWriteLine(@ScriptDir&"\file.txt", $searchdir & "\" & $file & @CRLF)
                EndIf
        WEnd
EndFunc   ;==>_filelist

clonecd 发表于 2008-8-9 15:16:47

原帖由 jhwl 于 2008-8-9 12:43 发表 http://www.autoitx.com/images/common/back.gif
最近有点忙,才看到你的邮件
以下是遍历搜索*.exe文件
_filelist("D:\jhwl")
Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*.*")
        If $search = -1 Then Return -1
        While 1
...


这个已经非常好了,可以稍作修改,排除以".exe"结尾的目录。

UID 发表于 2009-3-21 23:42:13

_filelist("D:")
Func _filelist($searchdir)
        $search = FileFindFirstFile($searchdir & "\*")
        If $search = -1 Then Return -1                ;如果没有匹配就退出
        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) = ".exe" Then                ;经过层层筛选,终于是找到文件了,匹配的写入列表文件
                       FileWriteLine(@ScriptDir&"\file.txt", $searchdir & "\" & $file & @CRLF)
                EndIf
        WEnd
EndFunc   ;==>_filelist

micro_snow 发表于 2009-5-11 15:09:19

ElseIf $file = "." Or $file = ".."

其中的點點代表什麽呀?

micro_snow 发表于 2009-5-11 15:10:07

($searchdir & "\*")

這裡的*號是不是寫我需要查找的EXE文件?

ydpd 发表于 2009-7-3 18:09:23

好东西,收藏

yzh016 发表于 2009-7-29 22:15:38

ddddddddddd

songtao 发表于 2009-8-14 20:07:33

不错,学习了。
页: [1] 2
查看完整版本: 求一个遍历目录然后将文件写入文本的源码!