Results 1 to 4 of 4

Thread: Check if a file exist suing a stored Proc

  1. #1
    Join Date
    May 2007
    Posts
    1

    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

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    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

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can use undocumented extended stored procedure

    exec master..xp_fileexist 'C:\yourfile.txt'

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •