Exists by file spec

File spec exists in VBS?

I tried many ways...

This does not work:

Option Explicit
Function OnClick(data)

	'Fails: Exists by file spec
	DOpus.Output "jpg " & DOpus.FSUtil.NewWild("c:\temp\*.jpg","f").match("c:\temp\*.jpg","f")
	DOpus.Output "jpg " & DOpus.FSUtil.NewWild("c:\temp\*.jpg","f").match("c:\temp\*.jpg")
	DOpus.Output "jpg " & DOpus.FSUtil.NewWild("c:\temp\*.jpg","f").match("*")
	
	DOpus.Output "not " & DOpus.FSUtil.NewWild("c:\temp\*.not","f").match("c:\temp\*.not","f")
	DOpus.Output "not " & DOpus.FSUtil.NewWild("c:\temp\*.not","f").match("c:\temp\*.not")
	DOpus.Output "not " & DOpus.FSUtil.NewWild("c:\temp\*.not","f").match("*")
	
End Function

From the documentation, the Wild.Match method:

Compares the specified string against the previously-parsed pattern, and returns True if it matches.

The wildcard object works on strings. It doesn't have anything to do with searching for files in folders, although you can combine it with other things to do that.

For example, you can use FSUtil.ReadDir to get a list of files below a folder, and then use a Wild object to filter those by wildcard.

A full example is here:

This works... sad there's no count method on newWild.

Option Explicit

Function OnClick(ByRef clickData)
	DOpus.Output "  Found matches " & wildExists(clickData,"*.png")
	DOpus.Output "  Found matches " & wildExists(clickData,"*.not")
end function

Function wildExists(data,spec)
	Dim folderEnum, wild, folderItem
	Set wild = DOpus.FSUtil.NewWild(spec, "f")
	Set folderEnum = DOpus.FSUtil.ReadDir(data.func.sourcetab.path)
	wildExists = false
	Do While (Not folderEnum.complete)
		Set folderItem = folderEnum.Next
		If (wild.Match(folderItem.name)) Then
			wildExists = true
			Exit Do
		End If
	Loop
End Function