Check if a file exist in a Query!

  • Hello!

    Are there any functions in SQL that tells me if a file in a dir exists or not?

    What's the synax?


    -Lars

    Please only reply to this newsgroup. All mails would be bounced back.

  • some code that can be used in DTS package to check if a file exists:

    Function Main()

    Dim objFSO

    Dim cFilePath

    Dim cFileName

    cFilePath = "<file path>"

    cFileName = "<file name>"

     

     -- instantiate the Scripting Object

      set objFSO = CreateObject("Scripting.FileSystemObject")

      With objFSO

        If .FileExists(cFilePath & cFileName) Then

          -- set on Global Variable that file exists............

        End if

      End With

      Set objFSO = Nothing

      Main = DTSTaskExecResult_Success

    End Function

    There are 10 types of people in this world - those that understand binary and those that don't

  • master..xp_fileexist 'c:\test'

  • Please avoid multiple postings on the same topic!

    It almost impossible to check who has answered what where already.

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=148946

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Sorry for the multipost. I only pressed send once, and it came up two times. Again - Sorry


    -Lars

    Please only reply to this newsgroup. All mails would be bounced back.

  • Try this

    /******************************************************************************************************

    ** Check to see if a file exists

    ******************************************************************************************************/

    DECLARE @chkfile INT

    DECLARE @exists BIT

    EXEC@chkfile = sp_MSget_file_existence 'C:\boot.ini', @exists = @exists output

    IF @exists = 1 -- The file exists

    PRINT 'File exists'

    ELSE

    PRINT 'File does not exist'

  • To determine if a file exists, not a job for a Query!

    To return, update or remove data -- a more proper use of T-SQL, hmm?

    For what purpose do you desire this technique? DTS may use VBScript as shown -- different from a query! DTS may contain a query, but the query itself: concerned it not, with file system contents!

Viewing 7 posts - 1 through 6 (of 6 total)

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