本帖最后由 smooth 于 2014-1-29 14:30 编辑
请教如何将全盘搜索到的文件存入数组?代码如下,这样只能用消息框的方式显示出来,想存入数组方便调用,谢谢!
Local $str
$Drive = DriveGetDrive("FIXED")
For $i = 1 To $Drive[0]
_Filelist($Drive[$i])
Next
MsgBox(0, 0, $str)
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
Else
_Filelist($SearchDir & "\" & $File)
EndIf
$str &= $SearchDir & "\" & $File & @CRLF
WEnd
EndFunc ;==>_Filelist
另:下面的代码能将找到文件存入数组,但是查找最后一个分区的文件,不能实现全盘搜索。
#include <Array.au3>
$Drive = DriveGetDrive("FIXED")
For $i = 1 To $Drive[0]
$sFiles = _FileListEx($Drive[$i] & "\")
Next
$aFiles = StringSplit($sFiles, "|")
_ArrayDisplay($aFiles,"")
Func _FileListEx($sDir)
If StringInStr(FileGetAttrib($sDir), "D") = 0 Then Return SetError(1, 0, "")
Local $oFSO = ObjCreate("Scripting.FileSystemObject")
Local $objDir
Local $aDir = StringSplit($sDir, "|", 2)
Local $iCnt = 0
Local $sFiles = ""
Do
$objDir = $oFSO.GetFolder($aDir[$iCnt])
For $aItem In $objDir.SubFolders
$sDir &= "|" & $aItem.Path
Next
For $aItem In $objDir.Files
$sFiles &= $aItem.Path & "|"
Next
$iCnt += 1
If UBound($aDir) <= $iCnt Then $aDir = StringSplit($sDir, "|", 2)
Until UBound($aDir) <= $iCnt
If $sFiles Then $sFiles = StringTrimRight($sFiles, 1)
Return $sFiles
EndFunc ;==>_FileListEx
请大家帮忙看下,谢谢! |