I understand that this thread is 5 years old, but I thought I would send another non-xpCmdShell alternative not related to the CLR. Details are given in the following code, and this is pretty simple stuff.
DECLARE @pPath VARCHAR(512);
SELECT @pPath = 'C:\Temp';
CREATE TABLE
(
RowNum INT IDENTITY(1,1),
ObjectName VARCHAR(512),
Depth TINYINT,
IsFile BIT,
Extension AS RIGHT(ObjectName,CHARINDEX('.',REVERSE(ObjectName))) PERSISTED
)
;
INSERT INTO
(ObjectName,Depth,IsFile)
EXEC xp_DirTree 'C:\Temp',1,1
;
SELECT * FROM
source
share