Avatar of michaelbarga
michaelbarga
 asked on

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 EXPLICIT
Const ForAppend = 8
DIM objFSO, objNet, objFile
DIM strPath, compName, strDiff, loFile, ldLast
strPath = "C:\Program Files\lotus\notes\data\mail\*.nsf"
 
SET objNet = CreateObject("WScript.NetWork")
compName = objNet.ComputerName
 
SET 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 IF
ELSE
      SET objFile = objFSO.OpenTextFile("noexistusernsf.txt", ForAppend, True)
      objFile.writeLine(compName & " *.nsf does not exist ")
END IF
 
SET objFile = NOTHING
 
WScript.Quit

Open in new window

Lotus IBMVB ScriptWindows Batch

Avatar of undefined
Last Comment
michaelbarga

8/22/2022 - Mon
sirbounty

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 & "\"))
Next
 
objFile.Close
 
Set objFile = Nothing
Set objFSO = Nothing
 
wscript.quit
 
Sub GetFolders(objFld)
  GetFiles (objFld.Files)
  For Each fld in objFld.SubFolders
    GetFolders (objFSO.GetFolder(fld))
  Next
End Sub
 
Sub 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
  Next
End Sub

Open in new window

bigjokey

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 = Nothing
	
End Function

Open in new window

michaelbarga

ASKER
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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
bigjokey

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
michaelbarga

ASKER
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.