JustCode : Loop all files and folders

I have started using this allot in the last few months. This JustCode example will show you all the files and folders in a specific folder.

LoopFolders(“c:\temp”)
 
Sub LoopFolders(sFullPath)
 Dim oFolder,oSubFolder,oFSO,oFile
 
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
 
If oFSO.FolderExists(sFullPath) Then
 Set oFolder = oFSO.GetFolder(sFullPath)
 
For Each oFile In oFolder.Files
 debug.Log(oFolder.Path + “” + oFile.Name)
 Next
 
For each oSubFolder in oFolder.SubFolders
 debug.Log(“Folder:”+ oSubFolder.Name)
 LoopFolders(oSubFolder.Path)
 Next
 
End If
 
Set oFSO = null
 Set oFolder = null
 Set oFile = null
 End Sub

JustCode : Work Out Value of Question On or Off Path

From time to time i find this very useful. This JustCode script will return the value of a question based on if it has an OffPath value or not.

Function WorkOutValue(oIOM,oQuestion,sReturn)
On Error Goto LogIt

if ( oQuestion.Response.value <> oQuestion.Info.OffPathResponse ) Then 

	if ( oQuestion.Info.OffPathResponse <> "" ) then
			
		select case sReturn
			Case = "V"
				WorkOutValue = ctext(oQuestion.Info.OffPathResponse)
			Case = "C"
				WorkOutValue = "{" + ctext(format(oQuestion.Info.OffPathResponse,"a")) + "}"
		End Select
	else
				
		select case sReturn
			Case = "V"
				WorkOutValue = ctext(oQuestion.Response.value)
			Case = "C"
				WorkOutValue = "{" + ctext(format(oQuestion.Response.value,"a")) + "}"
		End Select
		
	end if
Else
	
	select case sReturn
		Case = "V"
			WorkOutValue = ctext(oQuestion.Response.value)
		Case = "C"
			WorkOutValue = "{" + ctext(format(oQuestion.Response.value,"a")) + "}"
	End Select
End If

Goto SkipError

LogIt:
		
	oIOM.Terminate(Signals.sigError)
	
SkipError:

	On Error Goto 0	

		WorkOutValue = WorkOutValue
End Function

JustCode : Make a file readonly

Over the years i have written many scripts. This JustCode script will show you how to make a file read only and then take it off again.

Dim sFileName

sFileName = "MYFILE"

' Make it readonly
ShellExecute("attrib" ,,,"+r " + sFileName ,,0)

' Take of readonly
ShellExecute("attrib" ,,,"-r " + sFileName ,,0)

JustCode : Send Email via Lotus Notes

Want to send an email to someone using Lotus Notes. This script will help you do that.

' Tested on Notes Version 8.0

Dim Maildb
Dim MailDoc
Dim Body
Dim Session

'Start a session to notes
Set Session = CreateObject("Lotus.NotesSession")

Session.Initialize("PASSWORD_HERE")

Set Maildb = Session.GETDATABASE("", "NSFFILE_LOCATION_HERE")

If Not Maildb.IsOpen = True Then
Maildb.Open()
End If

'Create the mail document
Set MailDoc = Maildb.CREATEDOCUMENT()

MailDoc.ReplaceItemValue("Form", "Memo")
'Set the recipient
MailDoc.ReplaceItemValue("SendTo", "MyEmail@Myserver.com")
'Set subject
MailDoc.ReplaceItemValue("Subject", "Subject Text")

'Create and set the Body content
Set Body = MailDoc.CREATERICHTEXTITEM("Body")
Body.APPENDTEXT("Body text here")

'Example to create an attachment (optional)
Body.ADDNEWLINE(2)
Body.EMBEDOBJECT(1454, "", "MYFILELOCATION_HERE", "Attachment")

'Example to save the message (optional)
MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
MailDoc.ReplaceItemValue("PostedDate", Now())
MailDoc.SEND(False)

'Clean Up
Set Maildb = null
Set MailDoc = null
Set Body = null
Set Session = null