try this out... Declare @cmdStr nvarchar(1050) Set @cmdStr = 'DIR /a-d ' + 'c:\importData\' --Drop table #WebPages Create Table #dirOutput (Id [int] IDENTITY (1, 1) NOT NULL, Diroutput nvarchar(4000)) INSERT #dirOutput EXEC master.dbo.xp_cmdshell @cmdStr Create table #FileList ( Id int, CreatedDate datetime, FileSize int, Name nvarchar(1000) Primary Key (Id) ) Insert Into #FileList Select Id, CreatedDate = convert(Datetime,left(DirOutPut,17) + 'm'), FileSize_kb = round(convert(float,Replace(substring(dirOutPut,18,charindex(' ',dirOutPut,19)-18),',',''))/1024.0,0), Name = substring(dirOutPut,charindex(' ',dirOutPut,19)+1,len(dirOutPut)-charindex(' ',dirOutPut,19)) From ( Select Id, dirOutPut=Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(dirOutPut,' ',' '),' ',' '),' ',' '),' ',' '),' ',' '),' ',' '),' ',' '),' ',' ') from #dirOutput Where dirOutPut not like '%Volume in Drive%' and dirOutPut not like '%Volume Serial Number is%' and dirOutPut not like '%Directory of%' and dirOutPut not like '%Total Files Listed:%' and dirOutPut not like '%file(s)%' and dirOutPut not like '%dir(s)%' and dirOutPut is not null ) as Files-- Select * From #dirOutput Select * From #filelist Drop table #filelist Drop table #dirOutPut
Corey