|
多谢各位大侠
;在两个for循环处似乎没有起作用QQ547416979
;对比两个文件夹下不同文件的大小、版本、创建时间,例如文件夹一:1、2、3三个文件;文件夹二2、3、4三个文件;
;则要求取出1和2这两个文件的大小、版本、创建时间
#include <File.au3>
#include <Array.au3>
Global $LogFile ="DirGetFile2.ini"
Dim $afile[1]
Dim $num,$num1,$num2
Dim $i,$j
Dim $afile1[1]
Dim $flag1[1]
Dim $afile2[1]
Dim $flag2[1]
Dim $afile3[1]
$num=0
$num1=0
$num2=0
_filelist("E:\桌面liji\AutoIT测试")
$afile1=$afile
;MsgBox(0,"$flag1的数组长度",UBound($flag1))
ReDim $flag1[UBound($afile)-1]
For $i=0 To UBound($flag1)-2
$flag1[$i]=0
Next
;MsgBox(0,"$flag1的数组长度",UBound($flag1)-1);为什么-1
$num1=$num
;MsgBox(0,"$afile1的数组长度", UBound($afile1)-1)
;MsgBox(0,"$num1", $num1)
$afile=$afile3
;MsgBox(0,"重置后数组长度", UBound($afile))
$num=0
;MsgBox(0,"重置后$num的大小", $num)
_filelist("E:\桌面liji\AutoIT测试2")
$afile2=$afile
ReDim $flag2[UBound($afile)-2]
For $i=0 To UBound($flag2)-2
$flag2[$i]=0
;MsgBox(0,"flag数组元素值",$flag2[$i])
Next
;$num2=$num-$num1;$num2是数组长度,彼编号大一
$num2=$num
MsgBox(0,"$afile2数组长度", UBound($afile2)-1)
MsgBox(0,"$num2的大小", $num2)
;$f=FileOpen($LogFile,1)
For $i=0 To UBound($afile1)-2
;MsgBox(0,"$flag1", $flag1[$i])
For $j=0 To UBound($afile2)-2
;MsgBox(0,"$flag2", $flag2[$j])
If $afile1[$i]==$afile2[$j] Then
;If Not StringCompare($afile1[$i],$afile2[$j]) Then
$flag1[$i]=1
MsgBox(0,"$flag1", $flag1[$i])
$flag2[$j]=1
MsgBox(0,"$flag2", $flag2[$j])
;ContinueLoop
ExitLoop
Else
ContinueLoop
;$flag1[$i]=0
MsgBox(0,"$flag1", $flag1[$i])
;$flag2[$j]=0
MsgBox(0,"$flag2", $flag2[$j])
EndIf
Next
Next
$f=FileOpen($LogFile,1)
For $i=0 To UBound($afile1)-2
;MsgBox(0,"$flag", $flag1[$i]);测试flag值是否改变
If $flag1[$i]=0 Then
;FileWrite($f,$i+1&@TAB&$afile1[$i]&@CRLF&@CRLF)
$size = FileGetSize($afile1[$i])
FileWrite($f,$i+1&@TAB&$afile1[$i]&@CRLF&@CRLF&@TAB&"size(kb):"&$size/1024&@CRLF)
$ver=FileGetVersion($afile1[$i])
FileWrite($f,@TAB&"version:"&$ver&@CRLF)
$time = FileGetTime($afile1[$i],1)
$yyyymd = $time[0] & "/" & $time[1] & "/" & $time[2]
FileWrite($f,@TAB&"time:"&$yyyymd&@CRLF&@CRLF)
EndIf
Next
For $i=0 To UBound($afile2)-2
If $flag2[$i]=0 Then
;FileWrite($f,$i+1&@TAB&$afile1[$i]&@CRLF&@CRLF)
$size = FileGetSize($afile2[$i])
FileWrite($f,$i+1&@TAB&$afile2[$i]&@CRLF&@CRLF&@TAB&"size(kb):"&$size/1024&@CRLF)
$ver=FileGetVersion($afile2[$i])
FileWrite($f,@TAB&"version:"&$ver&@CRLF)
$time = FileGetTime($afile2[$i],1)
$yyyymd = $time[0] & "/" & $time[1] & "/" & $time[2]
FileWrite($f,@TAB&"time:"&$yyyymd&@CRLF&@CRLF)
EndIf
Next
FileClose($f)
Func _filelist($searchdir1)
$search1 = FileFindFirstFile($searchdir1 & "\*")
;$search2 = FileFindFirstFile($searchdir2 & "\*")
If $search1 = -1 Then Return -1
While 1
$file1 = FileFindNextFile($search1)
;$file2 = FileFindNextFile($search2)
If @error Then
FileClose($search1)
;FileClose($search2)
Return
ElseIf $file1 = "." Or $file1 = ".." Then
ContinueLoop
ElseIf StringInStr(FileGetAttrib($searchdir1 & "\" & $file1), "D") Then
_filelist($searchdir1 & "\" & $file1)
ContinueLoop
EndIf
$afile [$num] = $searchdir1 & "\"&$file1
$num += 1;最后多加了一次,num就是数组长度,彼编号大一
ReDim $afile [UBound($afile)+1];最后多加了一次
WEnd
;Return $afile
;Return $num;报错未定义先用,局部变量和全局变量
EndFunc ;==>_filelist
多谢各位大侠 |
|