You can use the undocumented stored procedure master.dbo.xp_fileexist to check if a directory exists.This code sample shows how you can use it:set nocount ondeclare @file_string varchar(400)select @file_string = 'c:\'create table #xp_fileexist_output ([FILE_EXISTS] int not null,[FILE_IS_DIRECTORY] int not null,[PARENT_DIRECTORY_EXISTS] int not null)insert into #xp_fileexist_outputexec master.dbo.xp_fileexist @file_stringif exists ( select * from #xp_fileexist_output where FILE_IS_DIRECTORY = 1 ) begin print 'File is a directory = '+@file_string endelse begin print 'File is not a directory = '+@file_string endselect * from #xp_fileexist_outputgodrop table #xp_fileexist_output
Results:File is a directory = c:FILE_EXISTS FILE_IS_DIRECTORY PARENT_DIRECTORY_EXISTS ----------- ----------------- ----------------------- 0 1 1
CODO ERGO SUM