//write -c "filename2 foo.txt" abc | write -c "filename 2bar.txt" def | echo -a $findfile($mircdir,filename2 *,1,1) and $findfile($mircdir,filename 2*,1,1)
For each pair of 1,1's, the 2nd is the folder depth to search, 1 = doesn't search subfolders
the 1st of the pair returns the Nth matching filename, and changing to 0 returns the total count of matches. If you just want to see if a matching file exists, it's faster to see if the 1st match is $null, rather than waste time finding potentially hundreds of matches.
This method won't be able to discern if the X in "filename4X text.txt" is a number or something else, so if your file naming scheme is chosen poorly you'd need to fetch the result to a variable then do a regex test against that.