I need a Batch or VBS Script that will look for *.nsf and then get the Modified Date from that file and then dump computer name and date to a text file
I am in need of a batch OR vbs script that will Search a Lotus Notes DIrectory looking for a location of *.nsf. There will only be one file labeld .nsf in this folder but it is named differently on each computer. I also need the script write to a text file and then write the computer name the modified date into a text file, as well as write to another text file if the the path doesn't exist. I have code that I have put together but it doens't allow me to search for Wildcards i.e *.nsf. If you need more information let me know. Also see my script and it should explain more.
OPTION EXPLICITConst ForAppend = 8DIM objFSO, objNet, objFileDIM strPath, compName, strDiff, loFile, ldLaststrPath = "C:\Program Files\lotus\notes\data\mail\*.nsf"SET objNet = CreateObject("WScript.NetWork")compName = objNet.ComputerNameSET objFSO = CreateObject("Scripting.FileSystemObject")IF objFSO.FileExists(strPath) THEN SET loFile = objFSO.GetFile(strPath) ldLast = loFile.DateLastModified strDiff = DateDiff("d",ldLast,DATE) IF strDiff < 2 THEN SET objFile = objFSO.OpenTextFile("recentusernsf.txt", ForAppend, True) objFile.writeLine(compName & " *.nsf Does Exist " & ldLast) ELSE SET objFile = objFSO.OpenTextFile("olderthan2usernsf.txt", ForAppend, True) objFile.writeLine(compName & " *.nsf Does Exist " & ldLast) END IFELSE SET objFile = objFSO.OpenTextFile("noexistusernsf.txt", ForAppend, True) objFile.writeLine(compName & " *.nsf does not exist ")END IFSET objFile = NOTHINGWScript.Quit
Here's one I wrote not too long ago that does just that.
It may require some tweaking, so let me know if you need something changed.
As-is it searches drives C: & E: for NSF files and reports the info to C:\NSFsFound.txt
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")Dim objFile : Set objFile = objFSO.CreateTextFile("C:\NSFsFound.txt")arrDrives = Array("C:", "E:")For Each drv in arrDrives GetFolders (objFSO.GetFolder(drv & "\"))NextobjFile.CloseSet objFile = NothingSet objFSO = Nothingwscript.quitSub GetFolders(objFld) GetFiles (objFld.Files) For Each fld in objFld.SubFolders GetFolders (objFSO.GetFolder(fld)) NextEnd SubSub GetFiles(arrFiles) For Each file in arrFiles strExt = LCase(objFSO.GetExtensionName(file.Name)) If strExt = "nsf" Then objFile.WriteLine file.Name & "," & file.Path & "," & file.DateLastModified End If NextEnd Sub
The FileExists function doesn't allow wildcard characters, so you have to iterate through all the files in the notes folder to find the .nsf file yourself.
Try this function in your code. You pass it the notes folder that you need to scan, and it will return the full path to the NSF file if it finds one, otherwise it returns an empty string. So instead of calling FileExists, use the following syntax in your code:
Change:
IF objFSO.FileExists(strPath) THEN
To:
strNSFFile = getNotesFileName(strPath)
If strNSFFile <> "" Then
Make sure to change the strPath variables to be only the path, (don't include the wildcard in it). And also dim the strNSFFile variable:
DIM strPath, compName, strDiff, loFile, ldLast, strNSFFile
strPath = "C:\Program Files\lotus\notes\data\mail\"
Hopefully that helps you.
Function getNotesFileName(strPath) Dim objFSO, objFolder, objFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.getFolder(strPath) For Each objFile in objFolder.Files If LCase(objFSO.GetExtensionName(objFile)) = "NSF" Then getNotesFileName = objFile.Path Exit For End If Next Set objFile = Nothing Set objFSO = Nothing Set objFolder = NothingEnd Function
Thanks Guys! Bigjokey I like how your defined the NSF file but I cannot get my script to work with it. Would it be possible for you to re-write my script to include your script. I guess its a Monday and I'm failing to comprehend on how to include your script into mine.
Thanks Bigjokey, the script doesn't error out anymore, unfortunately now all it will return is a text file called noexistusernsf.txt. Can you explain this scenario? I know the file exists in this location but now it is not seeing it, or is it just writing to the noexistusernsf.txt by default and the file is actually there???
Please help.
Thanks
michaelbarga
ASKER
Found only one issue with the script the NSF needed to be changed to lower case nsf and it worked fine.
It may require some tweaking, so let me know if you need something changed.
As-is it searches drives C: & E: for NSF files and reports the info to C:\NSFsFound.txt
Open in new window