When i use this code to get the bak filename,why the #tmpTable
last row is null?
--Configure extension procedure the cmd_shell enable
declare @backupfile_store_path varchar(200)
,@DynamicSql varchar(200)
exec sp_configure 'show advanced options',1;
reconfigure;
exec sp_configure 'xp_cmdshell',1;
reconfigure;
if (OBJECT_ID('tempdb.dbo.#tmpTable') is not null)
drop table #tmpTable --#tmpTable
--select OBJECT_ID('tempdb.dbo.#tmpTable')
create table #tmpTable
(
DBName varchar(200)
)
set @backupfile_store_path='E:\20131015'
/*using extended procedure xp_cmdshell to get the path and name*/
set @DynamicSql='cd /d "'+@backupfile_store_path+'"&&dir /a /b /s *.bak'
insert into #tmpTable exec xp_cmdshell @DynamicSql
select * from #tmpTable
When i use this command:
C:\Users\Administrator>cd /d e:\20131015
e:\20131015>dir /a /b /s *.bak>>c:\a.txt
e:\20131015>
The txt file's last row has a blank column,why it has a blank column?
It is about the windows dir
commmand,the last output is a blank line.