VBscript search for lister name using wildcards

I am trying to switch layouts using VBScript but I don't want to hard code the names into the script in case they change. In the working example below I have a lister called LCC001 - LTM - (L Drive). All my listers start with a similar but unique 6 character prefix. I want to be able to look up the name of a lister using a wildcard, in case the suffix changes. Is this possible?

Option Explicit
Function OnClick(ByRef clickData)
Const Quote = """"

Dim cmd,Switchlister

set cmd = clickData.Func.command

SwitchLister="Prefs LAYOUT="+Quote+"LCC001  -  LTM    -  (L Drive)"+quote+" LAYOUTCLOSELISTERS=yes"
cmd.RunCommand(SwitchLister)

End Function

An alternate approach would be to have the lister name as LCC001 and put the remainder in the lister description but I have not found a way for the lister description to be shown on the lister layout menu, next to the lister name.

You can get a list of all layouts by enumerating the *.oll files under /dopusdata\Layouts.

But if there was more than one * - LTM - (L Drive) layout, how would the script know which layout to open? And if there will never be more than one such layout, is the prefix needed at all? Are there some more hidden details to this problem that are important to solving it?

They are all unique, but the 3 pieces of information (LCC001, LTM, L Drive) are required to be displayed when it is selected from the lister layout menu.
I like the idea of enumerating the .oll files and then presumably using a For Each loop and some form of prefix wildcard lookup to get the full name.
To get me started, if you have any examples of getting a file list into a table using a Dopus alias path it would be appreciated.

This will get you the list of layout names, including proper handling of the layouts tree (if they aren't all at the top level) and skipping the System layouts:

option explicit

Dim FolderEnum, FolderItem, LayoutsPath, LayoutName

Set LayoutsPath = DOpus.FSUtil.Resolve("/dopusdata\Layouts")

' Make sure the path string has a \ on the end as we're going to be removing
' it from the start of other paths using string functions.
If Right(LayoutsPath,1) <> "\" Then
	LayoutsPath = LayoutsPath & "\"
End If

Set FolderEnum = DOpus.FSUtil.ReadDir(LayoutsPath, True) 'True=Recursive
Do Until FolderEnum.complete
	Set FolderItem = FolderEnum.next
	' Ignore folders. The FolderEnum recurses into them for us.
	If Not FolderItem.is_dir Then
		LayoutName = FolderItem
		' Remove LayoutPath from the start of paths.
		' Remove .oll extension, and skip files that don't have it.
		' Ignore files below the System folder (special layouts).
		If PrefixRemove(LayoutName, LayoutsPath) _
		And SuffixRemove(LayoutName, ".oll") _
		And (Not BeginsWith(LayoutName, "System\")) Then
			' Remove the extra "Folders" path level, if present.
			PrefixRemove LayoutName, "Folders\"
			' Now we have the layout name.
			DOpus.Output LayoutName
		End If
	End If
Loop

' ** Helpers *************************************************************

Function BeginsWith(str, prefix)
	If StrComp(Left(str, Len(prefix)), prefix, 1) = 0 Then
		BeginsWith = True
	Else
		BeginsWith = False
	End If
End Function

Function PrefixRemove(str, prefix)
	If BeginsWith(str, prefix) Then
		str = Mid(str, Len(prefix)+1)
		PrefixRemove = True
	Else
		PrefixRemove = False
	End If	
End Function

Function EndsWith(str, suffix)
	If StrComp(Right(str, Len(suffix)), suffix, 1) = 0 Then
		EndsWith = True
	Else
		EndsWith = False
	End If
End Function

Function SuffixRemove(str, suffix)
	If EndsWith(str, suffix) Then
		str = Mid(str, 1, Len(str)-Len(suffix))
		SuffixRemove = True
	Else
		SuffixRemove = False
	End If	
End Function
1 Like

Thanks Leo.

1 Like