Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Get list of files from dir and put in table

By Neil Jacobson,

This stored procedure reads the file names from a directory and stores just the names in a given table. It returns also the number of files present. The sp uses xp_cmdshell and so permissions are restricted to sysadmins and SQLAgentCmdExec. You can test with the following: Create Table ##tmp2 ( fldx nvarchar(255) ) Declare @FilePath nvarchar(2048) , @tblName nvarchar(255) , @FileCount int Set Nocount on Select @FilePath = 'C:\Test1' , @tblName = '##tmp2' , @FileCount = 0 EXEC master.dbo.sp_DirFiles @FilePath , @tblName , @FileCount OUTPUT Select * From ##tmp2 select 'Filecount = ', @FileCount drop table ##tmp2

Total article views: 1899 | Views in the last 30 days: 6
 
Related Articles
FORUM

syntax error /SET "\Package.Variables[user::p1].Properties[Value]";+"FilePath"

/SET "\Package.Variables[user::p1].Properties[Value]";+"FilePath"

FORUM

nvarchar -int

nvarchar -int

FORUM

FK selection (an nvarchar(30) column or four int columns)

FK selection (an nvarchar(30) column or four int columns)

FORUM

The process could not bulk copy out of table 'tblname'.

The process could not bulk copy out of table 'tblname'.

FORUM

Scripting help - Need a query to find filenames and filepaths under a certain directory

Scripting help - Need a query to find filenames and filepaths under a certain directory

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones