中国网络渗透测试联盟

标题: 快速度查找文件和目录的SQL语句 [打印本页]

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句
: u! u/ L( m8 G  p7 L$ L8 R' Q: G* t, q
CODE:2 F  q8 m& G7 v; G3 ?3 d
9 Z+ g7 p7 Y* x- B
drop table tmp;! ~2 ~6 c" _8 ~5 _3 }
create table tmp; R4 i6 S' h; s1 _1 Q6 d
(% V4 O* p1 ^) ^7 j" ]: \
[id] [int] IDENTITY (1,1) NOT NULL,
& ]& q0 t4 \% B/ q* Z( o* Q2 I$ K: ][name] [nvarchar] (300) NOT NULL,
# r# @" ?- q; @( t[depth] [int] NOT NULL,4 [1 k8 Z4 B& M
[isfile] [nvarchar] (50) NULL
7 Y: e& \, x2 g);
2 c# k8 P5 r. @* y4 d2 G
% H. r5 t1 p0 |' r- Vdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
8 {2 ~/ W9 S# oset @root='f:\usr\' -- Start root
! Q( i2 }& o' J* G, W* D1 V" ~set @name='cmd.exe'   -- Find file& ]3 n! j) a; s: n* U
insert into tmp exec master..xp_dirtree @root,0,1--' _7 f6 @8 I% [2 Q
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
/ `9 M9 R& y% Q* g( \/ F* L* rset @depth=(select top 1 depth from tmp where isfile=1 and name=@name)" _' |( z5 Y( S6 ?' Q, c, O
while @depth<>1 * p3 I8 j+ }# ^
begin ! |0 }; v- M# x* O
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
& O+ ]) `$ F6 Vset @depth=(select depth from tmp where id=@id)
$ s! R! ?. n* i/ u( ]1 g: c% t' L' Rset @name=(select name from tmp where id=@id)+'\'+@name
" K2 Z) q- Z9 M6 V: k2 [5 wend: g3 e7 h, F2 X' z/ i) e* L- p
update tmp set name=@root+@name where id=1" Z7 _3 b) b+ w- w
select name from tmp where id=1; X1 n4 g9 |! @& F' O
. ?8 c0 j7 R) h. S# J
查找目录的语句
' ~% q2 a7 b2 ], \* _# P$ @) @" a$ t# x5 @* B7 z5 V8 Z# z9 k% g, k

# Y& l2 h& X1 ~* T+ bCODE:
7 a9 Q6 r- U% E' b; e3 N! g$ x- V' @' v& x+ I0 B
& A/ F  g7 A: C, y; L3 r
drop table tmp;
# g# n$ E" i& r# j. ucreate table tmp
5 A# _; T9 a# o' L* d7 ?(5 F$ H9 Z, ]$ s9 Z1 t
[id] [int] IDENTITY (1,1) NOT NULL,
( d. _3 `! e7 j8 j3 o( R[name] [nvarchar] (300) NOT NULL,7 M" ]" V& j+ D. c
[depth] [int] NOT NULL& V0 K' |& |' W3 R
);
# A: O0 u9 U. U9 l/ V. b6 e2 V; j) I* [
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)$ G6 Y- V8 w  L3 X8 d
set @root='f:\usr\' -- Start root
3 {9 f8 w! L! _" aset @name='donggeer' -- directory to find1 D4 D6 k# N, p: e9 ^; x
insert into tmp exec master..xp_dirtree @root,0,0
- }) S0 _8 F2 P% B3 S# ?2 uset @id=(select top 1 id from tmp where name=@name) 4 ~) P: u1 c3 L" n# z  m! ?6 H1 {# h6 R0 B
set @depth=(select top 1 depth from tmp where name=@name)
! v, ~# n6 o, L' d& Xwhile @depth<>1
4 v3 @2 v/ o  F' Rbegin % A9 I2 p- W, A6 Y8 r
set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc); q: b. J, Q* i$ k! g
set @depth=(select depth from tmp where id=@id)
7 k7 c1 s: f) W6 Mset @name=(select name from tmp where id=@id)+'\'+@name
2 T+ H+ p* z% h! G2 _end update tmp set name=@root+@name where id=10 E9 ]+ R1 p& G
select name from tmp where id=1




欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/) Powered by Discuz! X3.2