I've built a "listener" job that runs a stored procedure every 15 minutes to see if a file has landed in an import directory. There are several files from different sources, and they can come in at any time of the day. The listener goes through a table of filenames using a cursor, then checks to see if each file exists using xp_cmdShell...
SET @Command = 'Dir "' + @FromFile + '"'; EXEC @xpRetVal = master.dbo.xp_cmdshell @Command, NO_OUTPUT
If it exists, the table contains the name of a stored procedure that will then import and process the file. The file is moved into an archive when that's complete.
My listener code works fine as far as finding a file that's in the directory. What I'm wondering is how do I know if the file has completely landed before I start importing it. Is there a way to tell?
Darrell H Burns