Working through a script that will search a file share for files whose names contain strings specified within an array. Also, if it encountered a directory where access is denied, it will skip the directory and continue to the next one.
Files found are then written to a log file. Below is what I have so far. I am having trouble getting it to actually search for the array strings. While I can get it to echo, it isn't actually "searching for the correct context.
'ON ERROR RESUME NEXT
Dim Sizereport
rootfolder = Inputbox("Enter directory/foldername: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)" & chr(10) & chr(10), _
"Getfoldersize", "C:\temp")
outputfile = "c:\temp\PasswordFiles_" & Month(now) & Day(now) & Year(now) & ".csv"
Set fso = CreateObject("scripting.filesystemobject")
if fso.fileexists(outputfile) then fso.deletefile(outputfile)
report = ""
arrContent = array("pass","password")
'Run checkfolder
FolderSizeReport = CheckFolder(rootfolder, 0)
Function CheckFolder(objCurrentFolder, SizeReport)
Set oFolder = fso.GetFolder(objCurrentFolder)
For Each oFile In oFolder.files
For Each strLine in arrContent
wscript.echo "Checking" & oFile & " for: " & strLine
If inStr(oFile.Name,arrContent(0)) Then
Report = Report & vbCrLf & oFolder & "\" & oFile.Name & "," & oFile.Size & "," & oFile.DateLastModified
SizeReport = SizeReport + oFile.Size
End If
Next
Next
'Recurse through all of the folders
For Each objNewFolder In oFolder.subFolders
CheckFolder objNewFolder, SizeReport
Next
CheckFolder = SizeReport
End Function
Report = Report & vbCrLf & "Total File Size =" & (FolderSizeReport/1024\1024) & "MB"
Set ts = fso.CreateTextFile (outputfile, ForWriting)
ts.write report
ts.close
Files found are then written to a log file. Below is what I have so far. I am having trouble getting it to actually search for the array strings. While I can get it to echo, it isn't actually "searching for the correct context.
'ON ERROR RESUME NEXT
Dim Sizereport
rootfolder = Inputbox("Enter directory/foldername: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)" & chr(10) & chr(10), _
"Getfoldersize", "C:\temp")
outputfile = "c:\temp\PasswordFiles_" & Month(now) & Day(now) & Year(now) & ".csv"
Set fso = CreateObject("scripting.filesystemobject")
if fso.fileexists(outputfile) then fso.deletefile(outputfile)
report = ""
arrContent = array("pass","password")
'Run checkfolder
FolderSizeReport = CheckFolder(rootfolder, 0)
Function CheckFolder(objCurrentFolder, SizeReport)
Set oFolder = fso.GetFolder(objCurrentFolder)
For Each oFile In oFolder.files
For Each strLine in arrContent
wscript.echo "Checking" & oFile & " for: " & strLine
If inStr(oFile.Name,arrContent(0)) Then
Report = Report & vbCrLf & oFolder & "\" & oFile.Name & "," & oFile.Size & "," & oFile.DateLastModified
SizeReport = SizeReport + oFile.Size
End If
Next
Next
'Recurse through all of the folders
For Each objNewFolder In oFolder.subFolders
CheckFolder objNewFolder, SizeReport
Next
CheckFolder = SizeReport
End Function
Report = Report & vbCrLf & "Total File Size =" & (FolderSizeReport/1024\1024) & "MB"
Set ts = fso.CreateTextFile (outputfile, ForWriting)
ts.write report
ts.close