As noted in another answer, xp_commandshell is problematic. SQL Server 2016+ allows another approach. See example
declare @tbl table(fn varchar(255), depth int,[isfile] int,primary key(fn))
declare @dir varchar(50)='C:\temp\' --'starting dir
insert @tbl
EXEC Master.dbo.xp_DirTree @dir,1,1 --dir, depth (1 - current only), file (0 - dirs only, 1+ - dirs and files)
delete @tbl where [isfile]=0 or fn not like '%.txt' --keep .txt files only
--select * from @tbl
--will insert into this table
create table #fileTbl (id int identity(1,1) primary key,fn varchar(255),txt varchar(max))
declare @fn varchar(255), @query nvarchar(4000)
select top 1 @fn=fn from @tbl
while @@ROWCOUNT>0--number of rows from the last query executed
begin
--dynamic query required to build OPENROWSET
set @query='insert #fileTbl(fn,txt) select '''+@dir+@fn+''',BulkColumn from openrowset(bulk ''c:\temp\'+@fn+''',single_blob) t'
exec sp_executesql @query
delete @tbl where fn=@fn
select top 1 @fn=fn from @tbl --proceed
end
select * from #fileTbl