中国网络渗透测试联盟
标题:
快速度查找文件和目录的SQL语句
[打印本页]
作者:
admin
时间:
2012-9-15 14:42
标题:
快速度查找文件和目录的SQL语句
查找文件的语句
, M$ t6 v/ p2 f F
# F- ^! S" @+ X. ]0 ~
CODE:
, {- }, l" ~3 p+ y% z1 \0 \
8 j6 ~4 X* a8 o$ x3 O; L3 @: c0 t
drop table tmp;
; J' e$ ]' C$ O8 L+ G
create table tmp
5 ^$ h% _# o, B; }. j0 ^
(
( s* B8 y9 }' v' o. J+ r8 F
[id] [int] IDENTITY (1,1) NOT NULL,
5 g0 R& q0 N+ q' A! P, ^
[name] [nvarchar] (300) NOT NULL,
6 T" x7 g) K0 R$ B
[depth] [int] NOT NULL,
9 j% G6 u+ z5 ~0 M k" g: Z
[isfile] [nvarchar] (50) NULL
' P$ Y1 N0 m5 H
);
0 J: e1 N* y" s/ e8 j
4 B& _% J* J. v) C& P( j% Z2 [
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
5 K- u* m0 K& l/ s( T$ E- r
set @root='f:\usr\' -- Start root
: {) f# k: o/ A% N6 J' f( [
set @name='cmd.exe' -- Find file
0 ?; J2 k% E. {! H0 I: v; x- j" V
insert into tmp exec master..xp_dirtree @root,0,1--
/ } h' i4 l3 Y3 Y" s
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
( O* Z, H$ G- `! ?
set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
$ {! q: M" C& z$ J$ p6 a+ l- y
while @depth<>1
" a# ^; r6 z8 \" m* J4 T5 A
begin
/ I8 ^: l" F4 ^$ J4 E: A- ]
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
5 C8 v: q' N6 v: ]: {8 t$ N
set @depth=(select depth from tmp where id=@id)
+ I/ L) i c. [' p# G2 k
set @name=(select name from tmp where id=@id)+'\'+@name
& v. Y4 v6 q3 b% l* x, W& f
end
& M u& {& q( e' G# h6 U- K
update tmp set name=@root+@name where id=1
8 ]* D7 Y3 j/ Q% }
select name from tmp where id=1
, N4 M; |1 {6 t8 @$ x2 I; s" S
9 p1 l) [3 w2 x# z* z
查找目录的语句
# P" M! w! H7 O0 S, @2 M$ {- G
+ y4 B$ P S- z. }& {; Y6 u3 V; G
; c2 e7 M c* v
CODE:
9 C+ {4 z! L% Y7 T" b
4 Y( @- X, ]& }
; x1 R1 \# K i. i. {) l
drop table tmp;
3 F) }! S3 N6 t* ?- _6 h6 `4 d
create table tmp
3 f% r4 [, G: t; A7 x) Y
(
. ~% [7 v( ]& W% m3 M( h4 S0 @
[id] [int] IDENTITY (1,1) NOT NULL,
8 l* U7 k& }9 l3 ]4 w' ]# G
[name] [nvarchar] (300) NOT NULL,
3 ]& ~5 U- U$ O( C
[depth] [int] NOT NULL
7 [' ~# N0 |/ D
);
/ r" P! c' h" i: W7 e4 i/ |2 \& |
3 {, I7 W0 g2 X% _8 P
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
" U- ]2 o6 h, H+ i7 o/ y5 S
set @root='f:\usr\' -- Start root
7 A7 U; m' [) D X3 ^+ n! Q
set @name='donggeer' -- directory to find
8 v7 ~: R$ T1 t! ~- E, L
insert into tmp exec master..xp_dirtree @root,0,0
" D- i4 ~5 J" @7 t. U9 M, \! s
set @id=(select top 1 id from tmp where name=@name)
% N0 q8 l r9 n% S
set @depth=(select top 1 depth from tmp where name=@name)
+ o0 o, y- a9 [ C: n, T2 l3 K
while @depth<>1
" A4 S, V- X9 G) @9 |5 k3 o$ k
begin
0 [$ [' @, | E; f. r( u- S7 J( W+ f
set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
8 |/ B* s R8 @
set @depth=(select depth from tmp where id=@id)
3 r* L/ G9 i% [, e" r7 y9 l/ C! m) H: f
set @name=(select name from tmp where id=@id)+'\'+@name
9 K# @9 _3 H7 t
end update tmp set name=@root+@name where id=1
5 j2 j' B8 b: V! h* {. P; B# V
select name from tmp where id=1
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2