SQL Server:xp_dirtree未显示带扩展名的文件

时间:2018-02-21 07:47:07

标签: sql sql-server-2012

我正在尝试使用xp_dirtree获取所有备份文件。我没有扩展名的文件列表。我想获得所有带扩展名的文件。

Declare @FileName varChar(255)
Declare @cmdText varChar(255)
Declare @BKFolder varchar(255)

set @FileName = null
set @cmdText = null
set @BKFolder = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\'


create table #FileList (
FileName varchar(255),
DepthFlag int,
FileFlag int
)


--get all the files and folders in the backup folder and put them in temporary table
insert into #FileList exec xp_dirtree @BKFolder,0,1
select * from #filelist

--get the latest backup file name
select top 1 @FileName = @BKFolder + FileName from #FileList order by filename desc
select @filename

enter image description here

参考链接:http://www.playwithsql.com/2011/06/play-with-xpdirtree-to-get-files-and.html

0 个答案:

没有答案
相关问题