Here is how I solved it (I know you have been waiting on the edge of your seat)alter proc usp_WaitForFiles @Filename varchar(255), @Path varchar(255), @IntervalMins tinyint = 5, @TotalWaitHours tinyint = 6asset nocount on/******************************************************************************* Locals******************************************************************************/declare @EndTime datetime, @FileExistOut int, @CmdShellRet int, @WaitForTime datetime, @Cmd varchar(80), @File varchar(510), @ErrTxt varchar(100)select @EndTime = dateadd(hh,@TotalWaitHours,getdate()), @File = @Path + @Filename/******************************************************************************* File Exists Logic******************************************************************************/exec master..xp_FileExist @File, @FileExistOut OUTwhile @FileExistOut = 0 and @EndTime > getdate()begin select @WaitForTime = dateadd(mi, @IntervalMins, getdate()) waitfor time @WaitForTime exec master..xp_FileExist @File, @FileExistOut OUTend-- Time checkif not (@EndTime > getdate())begin select @ErrTxt = 'Exceeded total wait time for file ' + @File raiserror(@ErrTxt,10,1) returnend/******************************************************************************* File Ready Logic******************************************************************************/select @Cmd = 'ren ' + @File + ' ' + @Filename + '.recieved'exec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUTwhile @CmdShellRet = 1 and @EndTime > getdate()begin select @WaitForTime = dateadd(ss, 10, getdate()) waitfor time @WaitForTime exec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUTend-- Time checkif not (@EndTime > getdate())begin select @ErrTxt = 'Exceeded total wait time during copoy of file ' + @File raiserror(@ErrTxt,10,1) returnendselect @Cmd = 'ren ' + @File + '.recieved ' + @filenameexec @CmdShellRet = master..xp_cmdshell @Cmd, NO_OUTPUT-- Rename Error Handlerif @CmdShellRet = 1begin select @ErrTxt = 'Error renaming file ' + @File raiserror(@ErrTxt,10,1) returnendreturngo
Jay<O>