How to check if a directory exists using SQL Server?

I know this command will create a directory:

EXEC master.sys.xp_create_subdir 'C:\testing\' 

But how can I check if "C: \ testing" exists?

 IF EXISTS(... 
+8
sql directory sql-server xp-cmdshell
source share
1 answer
  CREATE TABLE ResultSet (Directory varchar(200)) INSERT INTO ResultSet EXEC master.dbo.xp_subdirs 'c:\' Select * FROM ResultSet where Directory = 'testing' 

Will return a list of subdirectories, then you can check the contents of the list.

+16
source share

All Articles