Tel. +44(0)208 4716864
info@softstuff-consulting.com
Follow us on Twitter  http://www.twitter.com/softstuffc
Softstuff Home Knowledgebase Home Contact Us Blog
GoldMine CRM SQL Server QuoteWerks Microsoft Excel Microsoft Word C# Windows XP Microsoft Dynamics CRM HEAT Sage CRM
Getting a list of filenames into a table

The following short TSQL will read files from disk into a table.
The example below will read all the files from the root of the C directory into a local table, but if you remember your DOS commands the path could be set to read any types of files from anywhere. The /B at the end of the DIR command is important as it returns only the filename with none of the other information like filesizes and attributes.


declare @dos varchar(255)
declare @fl table(filename varchar(255))

set @dos='DIR C:\*.* /B'
insert into @fl(filename)
exec xp_cmdshell @dos

select * from @fl where filename is not null

The select statement reads all the files listed, but it could easily be made more specific to get files matching a specific pattern if needed.

If this does not work on your system, then XP_CMDSHELL might not be enabled, see the other article in the knowledgbase.

04 August 2009  IB      SQL Server


Back To List

Did this article answer your question

 Yes

 No

 



 

Search our knowledgebase

Look In   For  
Enter a word or phrase to search for. eg. shrink

Enter your Email Address to receive the latest knowledgebase items delivered direct to your inbox.

Subscribe to the knowledgebase in your favourite RSS reader:   Plain RSS 2.0 Feed   Add to Google  Add to My Yahoo!

Note:
Softstuff accepts no responsibility for the use of information contained within this item. No warranties are implied or provided and it is advised that you have a working knowledge of the technologies contained, and we will not be held liable for system downtime, or data loss caused, unless we have specifically advised in writing to you that this is the case during the course of a support issue raised and accepted by us.
 

Copyright Softstuff Consulting 2007-2009