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
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\mai l\"
Hopefully that helps you.
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)
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\mai
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
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.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Please help.
Thanks
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