VBScript 5.8 on Windows 2008 Server.
I copied some code from another source to look for certain strings in files, and whilst this code works, I wanted to open it up to search for all files within a given drive/directory.
This is the code that worked:
I edited the code to open up the search to check for all files:
Although this works to a point (until it errors on a file), it eventually bombs on file permissions errors and "Process cannot access a file because it is being used by another process" error for files such as .lck files.
Can anyone tell me how to code in an ignore/skip rule into this please?
Never touched VB before today, so be gentle!
Thanks in advance.
I copied some code from another source to look for certain strings in files, and whilst this code works, I wanted to open it up to search for all files within a given drive/directory.
This is the code that worked:
Code:
Dim FSO
Const START_DIR = "c:\"
Set FSO = CreateObject("Scripting.FileSystemObject")
set outFile = FSO.createTextFile( "c:\temp\findings.txt")
doFolder START_DIR
outFile.close
sub doFolder(path)
' WScript.echo "Doing folder " + path
Dim folder, files, file, subfolders,subfolder
set folder = FSO.getFolder(path)
set files = folder.Files
for each file in files
doFile path, file.path
next
set subFolders = folder.subFolders
For Each subfolder in subFolders
doFolder subfolder.path
Next
end sub
sub doFile( parent, path )
' WScript.echo "Found file " + path
if right(lcase(path),4) = ".txt" then
checklog parent, path
end if
end sub
sub checklog(parent, path)
' Wscript.echo "log file " + path
Set fl = FSO.opentextfile(path, 1)
Do While fl.AtEndOfStream <> True
line = fl.ReadLine
if InStr(line, "searchstringhere" ) > 0 then
output path
Exit Do
end if
Loop
fl.close
end sub
sub output(path)
outFile.writeLine(path)
end subCode:
sub doFile( parent, path )
' WScript.echo "Found file " + path
' if right(lcase(path),4) = ".txt" then
checklog parent, path
' end if
end subCan anyone tell me how to code in an ignore/skip rule into this please?
Never touched VB before today, so be gentle!
Thanks in advance.