How to enumerate files/folders using TSQL (xp_dirtree)

xp_dirtree or dir \b or xp_fileexist

all of them reside in master.dbo.

exec master.dbo.xp_dirtree 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL', 1, 0 — get directories
exec master.dbo.xp_dirtree 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL', 0, 1 — get files

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>