How do I verify my directory paths in my user tables

  • Is there a script that can be built to verify the existance of a file, assuming the file's directory is given in a specified field in a user table? 

    For example:

    I have a locator Column in my Media.dbo user table.  In that column for every entry I have a directory path (ex: //BCFILEMGR/Mediafiles/BCXP1/test.omf) Can you have SQL verify that the "test.omf" file actually exists at the location given? Assuming the volume indicated is mounted on the server.

     

    Thanks in advance

    'hboypro

  • There is an undocumented extended stored procedure that you can use for this.  It is xp_fileexist and resides in the master database.  Following is a sample execution -

    exec master..xp_fileexist 'x:\SQL_Backups\test.BKP'

    If the file exists, you will receive a '1' in the File Exists "column" of the output.

    Here's a sample of its use in a stored procedure -

         EXEC master..xp_fileexist @DestFile, @result output

         IF (@result = 0) 

          BEGIN

    -- Steve

  • Great, that's what I needed.

     

    Thanks.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply