Pequeño script matutino

19 11 2009

Tiene un arbol de directorios llenos de ficheros de log  creados hoy y quiere saber en que archivo esta el log o el dato de texto que necesita, a mi me ha pasado eso mismo esta mañana y me hecho este aborto de script:

'Busca una ocurrencia de texto en ficheros de logs dentro de un arbol de directorios dados.
'
'
'
basedir="E:\XXXXXX\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder(basedir)

Sub ShowSubFolders(Folder)
 For Each Subfolder in Folder.SubFolders

 Set objFolder = objFSO.GetFolder(Subfolder.Path)
 searchfile(objFolder)
 ShowSubFolders Subfolder
 Next
 Set Objfolder = Nothing
End Sub

Sub searchfile(folders)
 Set colFiles = folders.Files
 For Each objFile In colFiles
 Set found = objFSO.GetFile(objFile.path)
 foundcreated=found.DateLastModified
 extension=Split(found.path,".")
 If  day(date()) = day(foundcreated) AND month(date()) = month(foundcreated) AND year(date()) = year(foundcreated) Then
 If extension(1) = "log" Then
 'Busca en un path una ocurrencia de texto.
 search_text(found)
 End if
 End if
 Next

End sub 

Sub search_text(filefind)
'    wscript.echo filefind.path
 match="Error"
 Set objFSO_search = CreateObject("Scripting.FileSystemObject")
 Set objFile_search = objFSO_search.OpenTextFile( filefind.path , 1)
 strSearchString = objFile_search.ReadAll
 objFile_search.Close
 matched=InStr(strSearchString, match)
 If matched > 0 Then
 wscript.echo "Error encontrado en: " & filefind.path 'Blat aqui para avisarnos
 End if
 Set objFSO_search = Nothing
 set objFile_search = Nothing
 set matched = Nothing
End sub

Espero que les sea de utilidad algun dia para alguien….

Advertisement

Acciones

Información

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s




Seguir

Get every new post delivered to your Inbox.