中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句" T8 D6 V5 p% U3 w
1 ?$ F0 o+ ^* Q) H5 \. G
CODE:
/ R: G+ m6 O  X4 v8 T" {+ R) B  b* A& M. i0 w* Z. i& r4 a- @3 N3 k5 ~
drop table tmp;' O9 J' ?) \" c" w
create table tmp9 D" K. N+ b: Q* [( v4 B8 M
(
9 q, o; T7 ]% X4 u8 B4 \3 g[id] [int] IDENTITY (1,1) NOT NULL,
5 D3 e* s5 T8 c& B+ q3 y[name] [nvarchar] (300) NOT NULL,8 n% g! S) p' K' L
[depth] [int] NOT NULL,
6 r: ^3 g( f1 q0 M* R9 L; ^[isfile] [nvarchar] (50) NULL
2 B! Z$ z4 O+ h);1 ~5 A+ `* ~' q# k6 Y5 d7 h( R' b

% ~; J, {' P$ y4 kdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
6 g* B6 W3 H! |" A. W! Sset @root='f:\usr\' -- Start root' S# Y2 {- @3 I
set @name='cmd.exe'   -- Find file
& v  w9 V* c4 W/ w5 \insert into tmp exec master..xp_dirtree @root,0,1--
6 o9 e6 _  ^* T& V2 Rset @id=(select top 1 id from tmp where isfile=1 and name=@name) 6 Y2 G- u3 V' k3 D
set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)/ f* D: I& R0 c0 O) e
while @depth<>1
5 ~" ^6 J, @7 Z; ^& W& z5 _8 b& nbegin
8 V2 `# X: o5 v/ f9 K/ [# Wset @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
8 f& Y4 ~6 X* F) x1 Iset @depth=(select depth from tmp where id=@id)
: j: i5 V- x- u& `1 gset @name=(select name from tmp where id=@id)+'\'+@name
6 r6 y, X' E$ @0 f4 Tend2 y) U4 k* M) d% {) ]
update tmp set name=@root+@name where id=1* @& E  q$ }4 {4 n, l
select name from tmp where id=1; g3 N& Q% i7 V# ~6 a; x, [' S

" z' R: c+ y3 J2 m" j* q" a8 i查找目录的语句
3 |. Y8 b; K2 ]8 g6 P8 `% e/ w+ j+ ?( g* a5 \* O5 Z

! D2 A+ r0 U* h) t1 U, k- M% |CODE:
# t9 \- V% i; \8 z7 l1 \' V! J8 N$ U
# u/ M" O( C: O' X4 O1 o$ }! ^
drop table tmp;
% O/ w1 w+ k( c# X9 J( F* [8 Ycreate table tmp
& }2 e) T% j, E8 Y4 `1 p(
; B9 G4 L! l, q9 ]1 y" T[id] [int] IDENTITY (1,1) NOT NULL,
: n" ^  N  U  x# p4 d[name] [nvarchar] (300) NOT NULL,- f" N7 F  z" y# R& T# d
[depth] [int] NOT NULL
6 }0 v/ U' R/ a& U% P);
- D7 }% R/ U1 A4 \0 d) `0 `
7 k  W  R) L- N8 k& udeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)8 K+ H* c7 e" z# [9 E' I' S2 B( }
set @root='f:\usr\' -- Start root
- Y& Y/ q9 M! ]# X8 o' hset @name='donggeer' -- directory to find
3 A& @. g+ B8 ?& l6 Zinsert into tmp exec master..xp_dirtree @root,0,0" B7 @# s; [, G2 v
set @id=(select top 1 id from tmp where name=@name) 3 A) L- c" v7 Q1 E
set @depth=(select top 1 depth from tmp where name=@name) $ e+ K% g& r. j7 q  j7 N: }6 I
while @depth<>1
6 z" V, r, p: a: Zbegin
. r7 ?' H: h5 X. v2 D0 nset @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
3 t5 z* Z$ d" S+ c2 \$ Eset @depth=(select depth from tmp where id=@id)
' c: G4 B5 u& W# Xset @name=(select name from tmp where id=@id)+'\'+@name * L' A4 }) k: V" G
end update tmp set name=@root+@name where id=1
5 V! g2 S9 g; p. ?8 U- vselect name from tmp where id=1




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