Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to read all file names in a directory using t-sql.

Problem is my query returns an empty result set even though my directory has files in it.

What I have tried:

DECLARE @Path nvarchar(500)
SET @Path = 'C:\ KWS\' --Change the path'

DECLARE @FindFile TABLE
(FileNames nvarchar(500)
,depth int ,isFile int)

INSERT INTO @FindFile
EXEC master.sys.xp_DirTree @Path,0,1
SELECT FileNames
FROM @FindFile WHERE isFile=1
Posted
Updated 14-Nov-19 2:46am

 
Share this answer
 
Comments
Maciej Los 14-Nov-19 5:24am    
5ed!
It may be a typo on your part, but there should not be a space in your path between the C:\ and KWS. If the space is actually there in the filesystem, you need to enclose the path in quote marks, '"C:\ KWS"'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900