Another option you could try. I know it is kludgy, so if it works, I wrote it. But if it doesn't work, I disown it.
CREATE TABLE #tmp(filenames VARCHAR(64));
INSERT INTO #tmp
EXEC xp_cmdshell 'dir /B c:\temp\* | findstr /I "test"';
-- see the files that match the pattern.
SELECT * FROM #tmp;
-- test whether there are any files that match the pattern
IF EXISTS (SELECT * FROM #tmp)
SELECT 'Yes, there are files that match the pattern c:\temp\*test*';
DROP TABLE #tmp;By the way, you can apply the filter either in the dir itself, or in findstr. Both are not necessary.