求一个遍历目录然后将文件写入文本的源码!
希望有源码的大大分享!................................................................答案在 6 楼和 8 楼 ! dir /s/b/e >a.txt
?? 谢谢版主,可能你没有理解我的意思!
我要做到的是一个遍历目录,遇到文件夹就继续向下递归循环!然后将文件都写入一个文本中!
以前论坛有一位朋友曾经写过,让我不小心把UDF给丢了! 将文件写入一个文本中?不大理解。 楼上的同志 文本和文本框是不一样的
我这里有这个UDF 本来想发出来的 但是这个破网吧把USB口给拔掉了我** 是不是这样的?
_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 谢谢!给你加钱! 最近有点忙,才看到你的邮件
以下是遍历搜索*.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 原帖由 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"结尾的目录。 _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 ElseIf $file = "." Or $file = ".."
其中的點點代表什麽呀? ($searchdir & "\*")
這裡的*號是不是寫我需要查找的EXE文件? 好东西,收藏 ddddddddddd 不错,学习了。
页:
[1]
2