2

How do I list All Subdirectory Folders within a Folder in SQL Server 2016?

Say I have a Folder called Test Foldertest which contains

FolderA
FolderB
FolderC

I want to list all three Folders, and ignore all individual files.

Currently trying to utilize EXEC xp_dirtree

How to list files inside a folder with SQL Server

  • I would suggest that using sql server to parse directories is the wrong tool for the job. It is designed to query data, not parse the OS directory structure. This should be done in your app or possibly with CLR. – Sean Lange May 20 '19 at 16:53
  • This is for a data warehouse, not an OLTP Application by the way –  May 20 '19 at 16:58

1 Answers1

2

Perhaps this will help

Declare @Table table (SubDir varchar(500),Depth int)

Insert into @Table
EXEC xp_dirtree  'C:\Foldertest',1,0

Select * From @Table
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66