本文转自:http://www.sqlservercentral.com/blogs/everyday-sql/2012/11/13/how-to-use-xp_dirtree-to-list-all-files-in-a-folder/

Last week I blogged about how to use an undocumented stored procedures to create folders.  This week we need to do the opposite.  We need to get a list of all files from a subfolder in order to process them.  In order to do that, we'll use another undocumented extended stored procedure; master.sys.xp_dirtree.  This stored procedure will display a list of every folder, every subfolder, and every file for path you give it.

 
Xp_dirtree has three parameters: 
 
  1. directory - This is the directory you pass when you call the stored procedure; for example 'D:\Backup'.
  2. depth  - This tells the stored procedure how many subfolder levels to display.  The default of 0 will display all subfolders.
  3. file - This will either display files as well as each folder.  The default of 0 will not display any files.

For today's example, we just want to display all of our backup files (*.BAK) in a particular folder. We need to all of the other parameters in order to show the files as well as any subfolders.

 
 
EXEC master.sys.xp_dirtree 'D:\Backup\TRON4\TEST2\MyDb1',0,1;
The output below will show us each subfolder and every file for the given directory.
 
 
 

[转]How to Use xp_dirtree to List All Files in a Folder的更多相关文章

  1. MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏

    ************************************************************ * 标题:MS SQLServer 批量附加数据库 * 说明:请根据下面的注释 ...

  2. SQL注入攻防入门详解

    =============安全性篇目录============== 本文转载 毕业开始从事winfrm到今年转到 web ,在码农届已经足足混了快接近3年了,但是对安全方面的知识依旧薄弱,事实上是没机 ...

  3. Security5:Execute AS 和 impersonate 权限

    principal 是统称,包括login,user,role等,可以向作为安全主体的用户授予权限,principal分为server level和database level. 登录名是Server ...

  4. SQL注入攻防入门详解(2)

    SQL注入攻防入门详解 =============安全性篇目录============== 毕业开始从事winfrm到今年转到 web ,在码农届已经足足混了快接近3年了,但是对安全方面的知识依旧薄弱 ...

  5. sp_MSforeachtable 与 sp_MSforeachdb

    在MSSQL里有许多不公开的系统存储过程,其中可能常用的sp_MSforeachtable和sp_MSforeachdb有这2个.分别用于遍历某数据库的每个用户表.每个数据库. sp_MSforeac ...

  6. Java程序员从笨鸟到菜鸟之(一百零一)sql注入攻击详解(二)sql注入过程详解

    在上篇博客中我们分析了sql注入的原理,今天我们就来看一下sql注入的整体过程,也就是说如何进行sql注入,由于本人数据库和网络方面知识有限,此文章是对网上大量同类文章的分析与总结,其中有不少直接引用 ...

  7. Sql-Server应用程序的高级注入

    本文作者:Chris Anley 翻译: luoluo [luoluonet@hotmail.com] [目 录] [概要] [介绍] [通过错误信息获取信息] [更深入的访问] [xp_cmdshe ...

  8. Windows Sqlserver Automatic Log Audit Via C/C++

    catalog . 数据库日志审计产品 . Mysql日志审计 . SQLServer日志审计 1. 数据库日志审计产品 Relevant Link: http://enterprise.huawei ...

  9. Deformity ASP/ASPX Webshell、Webshell Hidden Learning

    catalog . Active Server Page(ASP) . ASP.NET . ASP WEBSHELL变形方式 . ASPX WEBSHELL变形方式 . webshell中常见的编码转 ...

随机推荐

  1. DBCC--OPENTRAN

    返回最早开始的但仍在运行的事务 数据库 'DB1' 的事务信息. 最早的活动事务: SPID (服务器进程 ID): 60 UID (用户 ID): -1 名称          : user_tra ...

  2. ExceptionLess ASP.NET MVC 异常日志框架

    Exceptionless 一个开源的实时的日志收集框架,它可以应用在基于 ASP.NET,ASP.NET Core,Web API,Web Forms,WPF,Console,ASP.NET MVC ...

  3. westrac server security configure user info

    security userkey:westracpass:Set#@!123

  4. ElasticSearch的基本认识和基本操作

    1.1.  ElasticSearch(简称ES) ES即为了解决原生Lucene使用的不足,优化Lucene的调用方式,并实现了高可用的分布式集群的搜索方案,其第一个版本于2010年2月出现在Git ...

  5. Java基础学习篇---------String、集合的学习

    一.String常用的方法: 1. == 实质比较两个对象的地址数值 String a = "hello"  (hello为匿名对象) String a1 = "hell ...

  6. 四,memcached的机制

    memcached机制: 1,基于c/s架构,协议简单. (1)c/s架构,此时memcached为服务端,我们可以使用如PHP,c/c++等程序连接memcached服务器. (2)memcache ...

  7. 前端ajax传数据成功发送,但后端接收不到

    前几天遇到这样的问题,找了好久,是在ajax     contentType属性设置的问题. contentType默认是application/x-www-form-urlencoded    但是 ...

  8. Hector 入门

    导入jar包 为了能够使用hector操作Cassandra数据库,首先导入hector的jar包,注意根据实际情况修改版本号 <dependency> <groupId>me ...

  9. java在编译期和运行期都做了什么

    Java对象内存存储,引用传递,值传递详细图解 java对象在内存中的分配 编译过程: 编译器把一种语言规范转化为另一种语言规范的这个过程需要哪些步骤?回答这个问题需要参照<编译原理>,总 ...

  10. 六:MyBatis学习总结(六)——调用存储过程

    一.提出需求 查询得到男性或女性的数量, 如果传入的是0就女性否则是男性 二.准备数据库表和存储过程 create table p_user( id int primary key auto_incr ...