|
发表于 2006 年 5 月 28 日 07:19:50
|
显示全部楼层
Public Function Scan() ''开始扫描
if left(path,1)="/" then
path=Spath&Replace(path,"/","\")
else
Path=Spath&"\"&Replace(path,"/","\")
end if
If ScanType=1 then
Scanfile(Path)
ElseIf ScanType=2 Then
ScanDb()
Else
ScanFile(Path)
ScanDb()
End If
EndT=timer
RunTime=FormatNumber(EndT-Start)*1000
TotalSize=shb(TotalSize)
TotalImg=DbImg+Images
End Function
Private Sub ScanDB() ''扫描数据库。这里的路径难于判断,请在InsDb中更改(If AddNum=0 后)
Dim Rs,RetStr,ReBel,SQL
SQL="Select "&ColID&","&ColIMG&" From "&Table&" Order by "&ColID&" DESC"
''On Error Resume Next
If Conn ="" OR Table="" OR ColID="" OR ColIMG = "" Then
Exit Sub
Else
Set Rs = Server.CreateObject("ADODB.RecordSet")
Rs.Open SQL,conn,3,3
While Not Rs.EOF
RetStr=Rs(1)
ReBel="表"&Table&"中的"&ColImg&"列(ID:"&Rs(0)&")"
InsDb RetStr,ReBel,0,""
Rs.MoveNext
Wend
Rs.Close
Set Rs=Nothing
End If
End Sub
Private Sub ScanFile(PathStr) ''扫描文件。递归
Dim f,ff,fn,fd,fdn,RealPath,fr,fc
''Response.write PathStr&"<br>"
Set ff = fso.getfolder(pathstr)
Set f = ff.files
Set fd = ff.subfolders
If f.Count >0 Then
For Each fn In f
Files=Files+1
TotalSize=TotalSize+fn.Size
If ChkFileName(fn.Name) Then
sFiles=sFiles+1
If Right(PathStr,1) <> "\" Then
RealPath=PathStr&"\"&fn.Name
Else
RealPath=PathStr&fn.Name
End If
Set fr = FSO.OpenTextFile(RealPath,1)
fc=fr.ReadAll
''response.write RealPath&"<br>"
RegExpTest filter,fc,RealPath
End If
Next
End If
If fd.Count> 0 Then
For Each fdn In fd
Folders=Folders+1
dim temp
if right (PathStr,1) <> "\" then
temp=PathStr&"\"&fdn.Name
else
temp=PathStr&fdn.Name
end if
ScanFile(temp)
Next
End If
End Sub
Private Sub RegExpTest(Patrn, Strng,PathStr) ''查找图片
Dim RegEx, Match, Matches,Chk,ReImg,RetStr,ReBel,TheFile
Set RegEx = New RegExp
RegEx.Pattern = Patrn
RegEx.IgnoreCase = True
RegEx.Global = True
Set Matches = RegEx.Execute(Strng)
For Each Match in Matches
RetStr = Replace(Match.Value,"src=","")
RetStr = Replace(RetStr,"''","")
RetStr = Replace(RetStr,"""","")
Chk = 0
ReBel=GetFn(PathStr)
InsDb RetStr,ReBel,1,PathStr
Next
End Sub
Private Function GetExt(FullPath) ''获得文件扩展名,用于判断是否是扫描的文件类型
Dim Temp
If FullPath <> "" Then
Temp = Mid(FullPath,InStrRev(FullPath, "\")+1)
If InStr(Temp,".")>0 Then
GetExt=Mid(Temp,InStrRev(Temp, ".")+1)
Else
GetExt=Temp
End If
Else
GetExt = ""
End If
End Function
Private Function ChkFileName(Str) ''检测文件是否是要扫描的文件类型
Dim ar,i,fn
fn=GetExt(str)
ar=Split(ScanText,"/")
ChkFileName=False
For i=0 To ubound(ar)
If lCase(fn) =lCase(Trim(ar(i))) Then
ChkFileName=True
Exit Function
End If
Next
End Function
Private Function shb(n) ''显示字节数
If n<1024 Then
shb = n&"字节"
ElseIf n>1024 and n<1024*1024 Then
shb = formatnumber(n/1024,2)&"K"
ElseIf n>=1024*1024 and n <1024*1024*1024 Then
shb = formatnumber(n/(1024*1024),2)&"M"
Else
shb =formatnumber(n/(1024*1024*1024),2)&"G"
End If
End Function
Private Sub InsDb(RetStr,ReBel,AddNum,PathStr) ''分析图片是否有效,并添加到字典对象中
dim chk,ReImg,TheFile
If InStr(RetStr,"http://")>0 OR Instr(RetStr,"ftp://")>0 Then
ReImg=RetStr
Chk=-1
Else
RetStr = Replace(RetStr,"/","\")
If (Left(RetStr,1) = "\" ) Then
RetStr=SPath&Retstr
ElseIf Left(RetStr,3) = "..\" Then
dim temp
temp=GetPath(PathStr)
Do Until Left(RetStr,3) <> "..\" ''处理相对路径
Temp=Fso.GetParentFolderName(Temp)
RetStr=Mid(RetStr,4,len(RetStr)-3)
Loop
RetStr=Temp&"\"&RetStr
Else
If AddNum=0 Then
if left(RetStr,1)="\" then
RetStr=Path&"\"&Retstr
Else
RetStr=path&Retstr
End If
else
RetStr=getpath(Pathstr)&RetStr
End IF
End If
If FSO.FileExists(RetStr) Then
Chk=1
End If
ReImg=GetFn(RetStr)
End If
If Chk=0 Then
Exists=Exists+1
End if
If File.Exists(ReImg) then
Set TheFile=File.Item(ReImg)
If TheFile.Belong <> ReBel Then
TheFile.Belong=TheFile.Belong&"|"&Rebel
End If
Else
If (List=0 AND Chk =0) OR (List=1 And Chk=-1) Or (List=2 And Chk=1 ) Or List=3 Then
Set TheFile= New FileInfo
TheFile.FileName=ReImg
TheFile.Belong=ReBel
TheFile.Exists=Chk
File.Add ReImg,TheFile
Select Case ScanType
Case 1 Images=Images+1
Case 2 DbImg = DbImg+1
Case Else
If AddNum = 0 Then
DbImg = DbImg+1
Else
Images=Images+1
End If
End Select
End If
End If
End Sub |
|