中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句
0 V6 W+ ^# Z# Y$ @, F' G7 E, ]- u; F
CODE:
8 H% y: S0 {# s
  _) \& D9 ]8 G4 o' Sdrop table tmp;
! o- v4 W3 x* m* q; ?$ @create table tmp
# V& i  @5 K7 W% [(
' x3 Q- D$ Z- l$ y- Q: Y: g4 s5 h- q[id] [int] IDENTITY (1,1) NOT NULL,
. I0 `$ I% Z+ \' k[name] [nvarchar] (300) NOT NULL,% e" D2 Q% O, a/ a
[depth] [int] NOT NULL,! L1 T6 P) P, n6 N* J
[isfile] [nvarchar] (50) NULL) ~1 }# V! N  O# B% Y
);
( h# M+ N* g0 ~  v0 ^
2 Z7 }1 }) v$ o/ m) R: _  G' Bdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
7 P0 i$ I7 h( f, x( H3 V7 e6 R6 pset @root='f:\usr\' -- Start root
2 g+ N8 z7 G; k; B  nset @name='cmd.exe'   -- Find file
6 }- b- \3 K* E( f; M% @insert into tmp exec master..xp_dirtree @root,0,1--, d4 B  n* Y* e4 `1 w! C# m
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
! y# W+ x4 \. Y; L) q& wset @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
5 c7 O1 k5 Y3 q' T- }( ywhile @depth<>1
* I% t  R) \$ g) h. w3 r& E, Gbegin
/ Z& Q" K7 J: h" p8 dset @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
# m0 J; s- u2 [7 o1 pset @depth=(select depth from tmp where id=@id)
$ G6 C0 P. {. V9 _* bset @name=(select name from tmp where id=@id)+'\'+@name4 }+ d- i/ b4 w' q* z' p* b
end! h6 p& I% O$ @, Z+ m
update tmp set name=@root+@name where id=1( B! s4 o8 p1 M
select name from tmp where id=1% U  G& g1 `/ {0 u. z4 k$ w

+ C4 A9 ^) }# W# f% p) K查找目录的语句
; j3 V0 R% j. f2 E3 V% H4 z/ V6 _+ d1 G: M7 X9 o

8 |; ?0 c: Y5 H9 e4 x# \5 X8 S. \CODE:. s( Y2 Z* {8 I' n6 a7 J) ?" r

6 F3 U: |# M+ j& [& e, \  W3 @
5 V6 d; _6 s0 Q/ p# pdrop table tmp;
% m, v, q+ P# R4 R- q7 Fcreate table tmp
$ E" _$ D: u' o% f(
" q1 t& Y8 b; r% d$ I0 o! q" }( V[id] [int] IDENTITY (1,1) NOT NULL,
2 s  P; ~  _/ E( K$ V[name] [nvarchar] (300) NOT NULL,
4 k  D& ^  q: V1 D[depth] [int] NOT NULL
: M4 [; P: a, |);
  |  [5 \- F9 j# ?/ c- x! y; ~& g. G1 e
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
9 V+ `$ y, ~( C, _+ x- ]. o, S7 tset @root='f:\usr\' -- Start root
5 I9 \) w4 [6 T1 eset @name='donggeer' -- directory to find- X' X8 }: _2 E7 p0 O
insert into tmp exec master..xp_dirtree @root,0,06 Y* X1 _2 j* V" C( X7 A. i6 z
set @id=(select top 1 id from tmp where name=@name) 4 T* p9 h/ k( r1 _) ?1 l  b7 m
set @depth=(select top 1 depth from tmp where name=@name) 8 P9 a" w; M& C5 b+ {
while @depth<>1
0 g" W  T7 R5 m- g' s3 ?6 ^0 xbegin
4 ?  x( M1 d1 R9 Y$ m+ h2 Sset @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
+ b; M$ q$ J# }7 Z/ g" u2 v7 Jset @depth=(select depth from tmp where id=@id)
4 O9 T) ]# Y) S+ bset @name=(select name from tmp where id=@id)+'\'+@name
1 ?( j# M- W0 r3 q: x& tend update tmp set name=@root+@name where id=1& K. \6 \3 W  K" k
select name from tmp where id=1




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