中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句
9 c  J7 ^- O7 [; W, x
" q' d2 C  G  A, w- m0 jCODE:
. A" N) d1 c, G' y/ l! J, p
; s/ i8 ~! [$ _; h" v- O8 z' R; Sdrop table tmp;
3 {/ f6 o$ [' Q. w- T  Zcreate table tmp3 i7 Y0 N! x, g( U! v2 \2 ^
(
0 G/ I$ c! o, g; E[id] [int] IDENTITY (1,1) NOT NULL,
/ I* b! D0 N- g; R/ C5 w* t- e[name] [nvarchar] (300) NOT NULL,
1 P* B3 Q$ C, B2 n) s4 S[depth] [int] NOT NULL,. K, J, G. e9 f4 H
[isfile] [nvarchar] (50) NULL
; @  W/ q, b  x1 d2 {7 J3 c2 X);
9 {/ a  j; V4 o
' {  w& t- ]! n# ^' fdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
/ b0 {$ x+ Q$ c) o7 R7 @: x$ N% oset @root='f:\usr\' -- Start root, p: ^1 B& ~1 x/ u  S, }
set @name='cmd.exe'   -- Find file! K: t/ m+ d$ h% I& }( l
insert into tmp exec master..xp_dirtree @root,0,1--
# j6 }# c! I( y6 s# Aset @id=(select top 1 id from tmp where isfile=1 and name=@name)
( W6 _+ }7 i) F4 z6 e; Wset @depth=(select top 1 depth from tmp where isfile=1 and name=@name)+ H  T. Y; [8 b7 F6 B; g; X" s! W+ V
while @depth<>1
" t- K; I, x4 `1 P2 g1 x; Fbegin
2 A) L& Y0 c% ^5 u0 ~$ kset @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc) " w# {8 ^) ]3 z; U1 e+ ~
set @depth=(select depth from tmp where id=@id)   }# A# e  b1 X
set @name=(select name from tmp where id=@id)+'\'+@name
# \+ b# _3 `% @  Eend4 n, m! A  e: A0 A+ A7 T  @
update tmp set name=@root+@name where id=12 v( e# r$ W. s, \# v" N
select name from tmp where id=16 G' b  r( z& Q
& [; W) I) w& [) {, K
查找目录的语句0 O, |0 u' b+ k! I6 m7 G" s
2 `6 J" y3 W7 ]- T9 u0 |  R( h

9 P# I9 I" M( J/ _+ [; `" z7 n/ vCODE:) u1 T3 l% p6 s9 n

6 M* D7 Y9 \0 b4 |  [6 h% x) S
6 @! N' T. A, h4 I+ K7 Udrop table tmp;% S" a3 N( ~' v
create table tmp
$ n; @/ U3 {2 M+ ~. L(: R8 t% u* p' X9 V4 [8 B5 l+ |7 K8 {9 P
[id] [int] IDENTITY (1,1) NOT NULL,* q- u/ F! L/ m# I
[name] [nvarchar] (300) NOT NULL,6 H5 F/ {5 g8 T( \- o& v2 m
[depth] [int] NOT NULL% E* \7 C4 p3 T( o
);; I6 I4 p" `$ O+ f" w0 O0 R3 j* n, o
8 O. `$ x+ B4 I6 u+ Z+ d
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
9 K/ l/ Y* B; z7 Pset @root='f:\usr\' -- Start root
6 E- Y8 J! y. Q' |( T- X: V8 ~' Pset @name='donggeer' -- directory to find; f9 A8 ?) c) L& g+ g2 N- ~
insert into tmp exec master..xp_dirtree @root,0,0
: x; }, y4 {  C. lset @id=(select top 1 id from tmp where name=@name) 0 I# g0 b9 r$ C' p7 q, q
set @depth=(select top 1 depth from tmp where name=@name)
, V$ x3 }' C3 w$ Fwhile @depth<>1
& y% |8 S, p1 r* g9 jbegin
2 Z9 M' R, h2 C) T! [set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
# h* w+ P* |0 h* d9 z' kset @depth=(select depth from tmp where id=@id) + u7 K% ?& L9 d9 @$ \
set @name=(select name from tmp where id=@id)+'\'+@name 1 ~2 P  f3 o" T0 }* j
end update tmp set name=@root+@name where id=1
+ m" F) i# q4 l2 h/ @9 ~( l& @select name from tmp where id=1




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