SQL Server Performance


Discussion in 'SQL Server 2005 General Developer Questions' started by arkiboys, Jun 30, 2008.

  1. arkiboys Member

    I am using the following sql to find out if a particular file exists.
    How can I modify this query so that I can just pass the extension of the file and not the name?
    For example, in this example, I just want to see if there is a .txt file present and so do not want to pass the name just the .txt

    declare @ret int
    declare @FilePath varchar(50)

    select @FilePath='c:workfilename.txt'

    declare @tblFile table
    (FileExists bit, FileIsaDirectory bit, ParentDirectoryExists bit)

    insert into @tblFile
    EXEC master.dbo.xp_fileexist @FilePath

  2. tosc New Member

    Hi arkiboy,
    xp_fileexist with wild card doesn't work! perhaps you will do something like this:
    DECLARE @outfileex TABLE ( cmdshell_output VARCHAR(255) ) -- dir /B is bare format INSERT INTO @outfileex EXEC xp_cmdshell 'dir c:work*.txt /B' IF EXISTS ( SELECT * FROM @outfileex ) -- Do something SELECT * FROM @outfileex ELSE -- Do something else SELECT * FROM @outfileex

Share This Page