Hi, 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 Thanks 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 select FileExists from @tblFile
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