cancel
Showing results for 
Search instead for 
Did you mean: 

Does sp_list_directory() check whether the specified directory exists?

VolkerBarth
Contributor
2,540

I'm guessing the answer is no.

Before unloading to a file I want to assure that the according directory does exist, so I'm using sp_list_directory() for that. (I'm on 16.0.0.2673.)

Simply testing via

select count(*) from sp_list_directory('MyDirectoryPath');

does return 0 both for an empty and an non-existing directory.

Q: Is that by design, or is there a way to make sp_list_directory() return an error for a non-existing "root_path" argument?


Aside: The obvious workaround is to check the parent directory if it does contain the desired subdirectory.

Accepted Solutions (0)

Answers (1)

Answers (1)

we create a proxy table in a directory access server then run the procedure below not null result indicates directory exists.

ALTER FUNCTION "owner"."DirectoryConnectionTest"() RETURNS INTEGER BEGIN DECLARE @Result INTEGER;

SELECT COUNT(*) INTO @Result FROM ESTA.Outbox WHERE Permissions NOT like 'd%';

RETURN ( @Result );

EXCEPTION WHEN OTHERS THEN RETURN ( @Result ); END