Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list files inside a folder with SQL Server

Tags:

sql

sql-server

How do I list files inside a folder in SQL Server without using the xp_cmdshell stored procedure?

like image 232
John W. Mnisi Avatar asked Jul 19 '12 11:07

John W. Mnisi


People also ask

How do I read a directory in SQL Server?

Step 1 : Connect your SQL Server instance and open new query window in SSMS and enable SQLCMD mode in Query tab. Step 2: Copy and paste below query in query window. Step 3: Execute query and get all file name present in that folder.


1 Answers

You can use xp_dirtree

It takes three parameters:

Path of a Root Directory, Depth up to which you want to get files and folders and the last one is for showing folders only or both folders and files.

EXAMPLE: EXEC xp_dirtree 'C:\', 2, 1

like image 78
Matija Grcic Avatar answered Sep 21 '22 03:09

Matija Grcic