Hackoo Posted May 30, 2011 Share Posted May 30, 2011 (edited) SearchFileByName.vbs : This is a VBScript to find files by name and generate the search results in a table in HTML citing information on these files such that their paths, creation date, modification date, size and attributes. Update On 29/05/2011: Adding and Displaying Miniature differents types of images when searching Eg if the search includes image files will be displayed as thumbnails. if there is something to improve this script please post it. Thank you ! 'SearchFileByName.vbs © Hackoo Le 26/05/2011 : C'est un Vbscript pour rechercher des fichiers par leurs noms 'et générer le Résultat de recherche dans un Tableau en HTML en citant les informations 'sur ces fichiers tels que leurs Chemins ,la date de création,la date de modification,la Taille et leurs attributs 'Mise à jour Le 29/05/2011 : Ajout et Affichage des miniatures de diffrentes types d'images lors de la recherche 'Càd si la Recherche comporte des fichiers images elles seront affichées en miniatures Dim fso, OutFile, sDrv, sFName, sReport, sFile, sTitle ,strHTML sTitle = "Recherche des Fichiers Par leurs Noms" Set fso = CreateObject("Scripting.FileSystemObject") OutFile = "Recherche.html" If fso.FileExists(OutFile) Then fso.DeleteFile(OutFile) Set sReport = fso.OpenTextFile(OutFile, 8, True) sDrv = InputBox("Entrez la lettre du lecteur à la recherche (lettre seulement)" & vbcrlf&_ "ou bien " & vbcrlf & "(Saisissez * pour rechercher dans toutes les lettres de lecteur local)", sTitle) If sDrv = "" Then WScript.Quit sFName = InputBox ("Entrez le nom du fichier à rechercher (sans extension)", sTitle) If sFName = "" Then WScript.Quit strHTML="<html><body text=white><style type='text/css'>"&_ "a:link {color: #F19105;}"&_ "a:visited {color: #F19105;}"&_ "a:active {color: #F19105;}"&_ "a:hover {color: #FF9900;background-color: rgb(255, 255, 255);}"&_ "</style>" strHTML=strHTML &"<center><h2><B> <font color=Red>[COUNT] </font>Fichiers Trouvés dont le Nom est <font color=red>"""& sFName &""" </font> sur le lecteur <font color=red>"& UCase(sDrv) & ":</B></font></h2></center>"&_ "<center><body bgcolor=#1234568><table border='3' cellpadding='1' style='border-collapse: collapse; font size:11pt' bordercolor='#CCCCCC' width='100%' id='Table1'></center>" & _ "<td><center><strong>Chemin :</strong></center></td>"&_ "<td><center><strong>Date de Création :</strong></center></td>"& _ "<td><center><strong>Date de Modification :</strong></center></td>"&_ "<td><center><strong>Taille :</strong></center></td>"&_ "<td><center><strong>Attributs:</strong></center></td>" If sDrv = "*" Then Dim d,dc,racine Set fso = CreateObject("Scripting.FileSystemObject") Set dc = fso.Drives For Each d in dc racine = d.Driveletter & ":" If d.IsReady Then GetResults racine , sFName End If Next Else GetResults sDrv & ":", sFName End If sReport.WriteLine strHTML &"</table></body></html>" Wscript.CreateObject("WScript.Shell").Run OutFile Sub GetResults(drv, fname) Dim sWQL, oFile, sAttrib,sFilePath,size ext = Array("png","jpg","jpeg","gif","bmp","psd","tif") sWQL = "select * from cim_datafile where Drive='" & _ drv & "' AND FileName = '" & fname & "'" Results = 0 For Each oFile In GetObject("winmgmts:").execquery(sWQL) Results = Results + 1 sFile = oFile.Name Set f = fso.GetFile(sFile) SizeKo = Round(FormatNumber(f.Size)/(1024),1) & " Ko" 'Taille en Ko avec 1 chiffre après la Virgule SizeMo = Round(FormatNumber(f.Size)/(1048576),1) & " Mo" 'Taille en Mo avec 1 chiffre après la Virgule SizeGo = Round(FormatNumber(f.Size)/(1073741824),1) & " Go" 'Taille en Go avec 1 chiffre après la Virgule If f.size < 1024 Then Size = f.size & " Octets" elseif f.size < 1048576 Then Size = SizeKo elseif f.size < 1073741824 Then Size = SizeMo else Size = SizeGo end if sFilePath = f.Path If oFile.Archive Then sAttrib = "Archive " If oFile.Compressed Then sAttrib = sAttrib & " Compressé " If oFile.Encrypted Then sAttrib = sAttrib & " Crypté " If oFile.Hidden Then sAttrib = sAttrib & " Caché " If oFile.System Then sAttrib = sAttrib & " Système " If oFile.Readable Then sAttrib = sAttrib & " Lecture " If oFile.Writeable Then sAttrib = sAttrib & " Ecriture " If UCase(ext(0)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(1)) = UCase(fso.GetExtensionName(oFile.Name))or UCase(ext(2)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(3)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(4)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(5)) = UCase(fso.GetExtensionName(oFile.Name)) or UCase(ext(6)) = UCase(fso.GetExtensionName(oFile.Name)) Then ImgFileName = oFile.Name strHTML=strHTML & "<tr><td><a target=_Blank href='"& sFilePath &"'>"&ImgFileName&"<br><img src='"& sFilePath &"' border=1 height=50 width=80></center></td><td><center>" & f.DateCreated & "</center></td>" & _ "<td><center>" & f.DateLastModified & "</center></td><td><center>"& Size & "</center></td>"&_ "<td><center>" & sAttrib & "</center></td></tr>" else strHTML=strHTML & "<tr><td><a target=_Blank href='" & sFilePath & "'>" & _ sFilePath & "</a></td><td><center>" & f.DateCreated & "</center></td>" & _ "<td><center>" & f.DateLastModified & "</center></td><td><center>"& Size & "</center></td>"&_ "<td><center>" & sAttrib & "</center></td></tr>" end if Next strHTML = Replace(strHTML, "[COUNT]", Results) End Sub Edited May 30, 2011 by Hackoo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.