DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to find files with the xp_fileexist command?

The following Microsoft SQL Server T-SQL code sample illustrates how to apply the undocumented xp_fileexist with result returned in a table variable:

DECLARE @File TABLE (      FileExists smallint,

                                              InDirectory smallint,

                                              ParentDirExists smallint);

SET NOCOUNT ON;

DECLARE @FileName varchar(255);

SELECT @FileName='C:\config.cfg';

 

INSERT @File;

EXEC Master.dbo.xp_fileexist @filename;

 

SELECT * FROM @File;

GO

 

FileExists

InDirectory

ParentDirExists

1

0

1

 

-- Alternate script

DECLARE @Exists INT;

DECLARE @FileName varchar(255);

SELECT  @FileName = 'C:\config.cfg';

 

EXEC master.dbo.xp_fileexist @FileName, @Exists OUT;

 

SELECT [Exists] = @Exists;

 

Exists

1

 

Related article:

Finding Files: Part 1 T-SQL

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE