Forum de discussion
Forum « Programmation ASP » (archives)
Re: recherche, FSO et IIX
Envoyé: 7 octobre 2002, 7h13 par Four
rechercher dans les sous-répertoires de /tqm/...
Merci du coup de main...
---------------------------
<html>
<head><title>Recherche Fichiers</title>
</head>
<body>
<%@LANGUAGE="VBSCRIPT"%>
<%
Response.AddHeader "Pragma", "No-Cache"
Response.CacheControl = "Private"
server.scripttimeout = 600
%>
<center>
Recherche de fichiers<br>
<%
dim filecounter, searchtext, directory 'dimention variables
dim fcount, fsize
filecounter = 0
searchtext = Trim(request("SearchText"))
directory = Trim(request("Directory"))
if directory = "" then directory = server.mappath ("\tqm")
'Write the Search Form to the page
response.write "<form action='FindFiles.asp' method=get>Search For:" & _
" <input type=text name=SearchText size=20 value=" & Chr(34) & searchtext & _
Chr(34) & "> Change Directory: <select size='1' name='Directory'><option value='0.0 System'>0.0 System</option><option value='0.1 Allgemeines'>0.1 Allgemeines</option><option value='1 Management'>1 Management</option><option value='2 Ressourcen'>2 Ressourcen</option><option value='3 Leistungserbringung'>3 Leistungserbringung</option><option value='4 Zufriedenheitsmessungen'>4 Zufriedenheitsmessungen</option><option value='5 Finanz- und Leistungskennzahlen'>5 Finanz- und Leistungskennzahlen</option></select> <input type=submit value=' Rechercher '></form><br></div>"
if searchtext <> "" Then 'if there is a file to search for then search
response.write "<table border=0 width='100%'>"
response.write "<tr><th width='60%'>File Name</th><th width='10%'>File Size</th><th width='30%'>Date Modification</th></tr>"
'create the recordset object to store
'the filepath, filename, filesize and last modified date
set rs = createobject("adodb.recordset")
rs.fields.append "FilePath",200,255
rs.fields.append "FileName",200,255
rs.fields.append "FileSize",200,255
rs.fields.append "FileDate",7,255
rs.open
Recurse directory 'call the subroutine to traverse the directories
Sub Recurse(Path)
'create the file system object
Dim fso, Root, Files, Folders, File, i, FoldersArray(1000)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set Root = fso.getfolder(Path)
Set Files = Root.Files
Set Folders = Root.SubFolders
fcount = 0 'zero out the file count variable
'traverse through the subdirectories in the current directory
For Each Folder In Folders
FoldersArray(i) = Folder.Path
i = i + 1
Next
'traverse through the files in the current folder or subfolder
For Each File In Files
'check if the search string is found
num = InStr(UCase(File.Name), UCase(searchtext))
'if it is then update the recordset and sort it
if num <> 0 then
filecounter = filecounter + 1
rs.addnew
rs.fields("FilePath") = File.Path
rs.fields("FileName") = File.Name
rs.fields("FileSize") = File.Size
rs.fields("FileDate") = File.DateLastModified
rs.update
rs.Sort = "FileName ASC"
end if
Next
'recurse through the current directory until
'all subfolders have been traversed
For i = 0 To UBound(FoldersArray)
If FoldersArray(i) <> "" Then
Recurse FoldersArray(i)
Else
Exit For
End If
Next
End Sub
'if files were found then write them to the document
If filecounter <> 0 then
filecounter = 0
do while not rs.eof
filecounter = filecounter + 1
response.write "<tr><td width='50%' valign=top><a href=""" & rs.fields("FilePath") & """>" & rs.fields("FileName") & "</td><td width='10%' align=right valign=top>"
'get the file size so we can
'assign the proper Bytes, KB or MB value
fsize = CLng(rs.fields("FileSize"))
'if less than 1 kilobyte then it's Bytes
if fsize >= 0 And fsize <= 999 then
fnumber = FormatNumber(fsize,0) & " Bytes"
end if
'if 1 KB but less then 1 MB then assign KB
if fsize >= 1000 And fsize <= 999999 then
fnumber = FormatNumber((fsize / 1000),2) & " KB"
end if
'if 1 MB or more then assign MB
if fsize >= 1000000 then
fnumber = FormatNumber((fsize / 1000000),2) & " MB"
end if
'write each file and corresponding info to the document
response.write fnumber & "</td><td width='30%' align='center'>" & rs.fields("FileDate") & "</td></tr>"
rs.movenext
loop
response.write "</table>" 'end the table
else
'no files were found
end if
end if
%>
</div>
</center>
<p> </p>
-- <%=Directory%>
</body>
</html>
Réponses
|