I need to check if a file exists on our server, and if it does, then execute code.
I know I can use the following code to do this:
DECLARE @fileExists int
EXEC master..xp_fileexist '\\server\feed.txt', @fileexists OUT
IF @fileExists = 1 -- The file exists
PRINT 'File Exists' -- Do what you want here
PRINT 'File DOES NOT EXIST'
My issue though is that the filename (file.txt) is not standard like this, and changes everyday with the date appended to the end. For instance, today's file looks like this: feed_23022021
I found that I cannot use a wildcard search with the xp_fileexist command such as: EXEC master..xp_fileexist '\\server\feed_*.txt', @fileexists OUT
We will only ever have one file in this directory at a time, so how would one go about checking if the file exists and if it does, then process it?
Any help is appreciated.