-
Check if a file exist suing a stored Proc
Hi there,
Does anyone know how to check if a file exist in a specific location using a stored procedure(SP)? The fact is that the file gets created using a SP, emailed to certain and then deleted. But sometimes, when some steps fail in the SP, then the file does not get deleted. And the next time the job runs, the steps keep on failing to create a new file coz it already exist. So I want to check beforehand if the file exist or not.
Please advise
-
If you have permissions to do so, you can use the xp_cmdshell extended stored procedure to execute dos commands:
DECLARE @cmd varchar(500)
SET @cmd = 'if exist c:\YourFile (do something)'
EXEC master..xp_cmdshell @cmd
-
You can use undocumented extended stored procedure
exec master..xp_fileexist 'C:\yourfile.txt'
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|