Using T-SQL to Query a File System Folder
14,209
Solution 1
You can use xp_cmdshell.
Example:
EXECUTE master.dbo.xp_cmdshell 'DIR "C:\YourDirectory\" /A-D /B'
There's a good, full example with more options here.
Solution 2
CLR integration is also an option, if you're not comfortable with allowing xp_cmdshell to be executed.
![George Johnston](https://i.stack.imgur.com/7ZpOD.jpg?s=256&g=1)
Author by
George Johnston
Updated on June 20, 2022Comments
-
George Johnston about 2 years
Is it possible to query a folder in TSQL, from SQL Management Studio, and return a list of file names? If so, how?