[已解决]如何快速将本地文件连同文件size遍历写入数组?
本帖最后由 palkiller 于 2012-8-6 11:50 编辑#include <Array.au3>
#Include <File.au3>
#NoTrayIcon
$begin=TimerInit()
$local_files=_FileListToArray(@WindowsDir&"\system32\","*",1)
Dim $f
For $i=1 To $local_files
$lfile_size=size(FileGetSize(@WindowsDir&"\system32\"&$local_files[$i]))
__ArrayAdd($f,$local_files[$i],$lfile_size)
Next
$time=TimerDiff($begin)
_ArrayDisplay($f,"用时"&Round($time/1000,2)&"秒")
Func __ArrayAdd(ByRef $avArray, $vValue0, $vValue1 = '', $0_auto = 1)
If Not IsArray($avArray) Then Return SetError(1, 0, -1)
Local $iUBound = UBound($avArray)
If UBound($avArray, 0) = 1 Then
If $0_auto And $avArray = $iUBound-1 Then $avArray += 1
ReDim $avArray[$iUBound + 1]
$avArray[$iUBound] = $vValue0
ElseIf UBound($avArray, 0) = 2 Then
If $0_auto And $avArray = $iUBound-1 Then $avArray += 1
ReDim $avArray[$iUBound + 1]
$avArray[$iUBound] = $vValue0
$avArray[$iUBound] = $vValue1
ElseIf UBound($avArray, 0) > 2 Then
Return SetError(2, 0, -1)
EndIf
Return $iUBound
EndFunc
Func size($size)
If $size<1024 Then
$size=$size&"B"
ElseIf $size>=1024 And $size<1048576 Then
$size=Round($size/1024,2)&"KB"
ElseIf $size>=1048576 And $size<1073741824 Then
$size=Round($size/1048576,2)&"MB"
ElseIf $size>=1073741824 And $size<1099511627776 Then
$size=Round($size/1073741824,2)&"GB"
Else
$size=Round($size/1099511627776,2)&"TB"
EndIf
Return $size
EndFunc上面的代码遍历一个3000多文件的文件夹,耗时10秒多,太悲催了...不知道各位达人有没有更快捷的方法,求指点... ReDim 太耗时 #include <Array.au3>
#include <File.au3>
$begin = TimerInit()
$local_files = _FileListToArray(@WindowsDir & '\system32\', '*', 1)
Dim $f[$local_files + 1] = [[$local_files]]
For $i = 1 To $local_files
$lfile_size = size(FileGetSize(@WindowsDir & '\system32\' & $local_files[$i]))
$f[$i] = $local_files[$i]
$f[$i] = $lfile_size
Next
$time = TimerDiff($begin)
_ArrayDisplay($f, '用时' & Round($time / 1000, 2) & '秒')
Func size($size)
If $size < 1024 Then
$size = $size & 'B'
ElseIf $size >= 1024 And $size < 1048576 Then
$size = Round($size / 1024, 2) & 'KB'
ElseIf $size >= 1048576 And $size < 1073741824 Then
$size = Round($size / 1048576, 2) & 'MB'
ElseIf $size >= 1073741824 And $size < 1099511627776 Then
$size = Round($size / 1073741824, 2) & 'GB'
Else
$size = Round($size / 1099511627776, 2) & 'TB'
EndIf
Return $size
EndFunc ;==>size {:face (356):}多谢A大...
页:
[1]