Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 xp_fileexists

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2008-06-30 : 07:47:27
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:\work\filename.txt'

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

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

select
FileExists
from
@tblFile

nathans
Aged Yak Warrior

938 Posts

Posted - 2008-06-30 : 17:52:42
I dont believe a wildcard (*.txt) is possible in xp_fileexists. You can adapt Nigel's method here to do what you want:

http://www.nigelrivett.net/SQLTsql/s_ProcessAllFilesInDir.html


Nathan Skerl
Go to Top of Page
   

- Advertisement -