Get Files names from Folder | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Get Files names from Folder

Hi Gurus!, Is there anyway I can get all all file names from a folder in T-SQL? I tried using FileSystem Object. But no success. In VB if create a Folder object then you get a collection. And then you can loop through the collection to get the files name. But how can we do this in T-SQL? Please help.
Thanks a million Regards
Sachin

see
http://www.nigelrivett.net/SQLTsql/ImportTextFiles.html That gets all the filenames from a folder with a file mask. Ignore the bit that imports and archives the files.
That looks over-complicated.<br /><br />Try this instead.<br /><br /><pre id="code"><font face="courier" size="2" id="code">master..xp_dirtree ‘&lt<img src=’/community/emoticons/emotion-4.gif’ alt=’;p’ />ath&gt;’,1,1</font id="code"></pre id="code"><br /><br />The last column indicates whether the item is a file or a directory.<br /><br />Hope that helps,<br /><br /><br /><br /><blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by nigelrivett</i><br /><br />see<br /<a target="_blank" href=http://www.nigelrivett.net/SQLTsql/ImportTextFiles.html>http://www.nigelrivett.net/SQLTsql/ImportTextFiles.html</a><br /><br />That gets all the filenames from a folder with a file mask. Ignore the bit that imports and archives the files.<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />Karl Grambow<br /><br />www.sqldbcontrol.com

Thanks a million Nigelrivett, U made my life so easy. You are star. I used the the same logic and it worked for me. Thanks again. Regards
Sachin
]]>