views:

88

answers:

2

Is it possible to query a folder in TSQL, from SQL Management Studio, and return a list of file names? If so, how?

+7  A: 

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.

AdaTheDev
+4  A: 

CLR integration is also an option, if you're not comfortable with allowed xp_cmdshell being executed.

http://msdn.microsoft.com/en-us/library/ms345136%28SQL.90%29.aspx

ScottE
+1 because I personally like the features offered by this mechanism - they have come in very useful to me for all kinds of tasks that are obtuse in TSQL. And +10 to Microsoft for creating this .NET integration feature in SQL Server.
John K