中国网络渗透测试联盟
标题:
快速度查找文件和目录的SQL语句
[打印本页]
作者:
admin
时间:
2012-9-15 14:42
标题:
快速度查找文件和目录的SQL语句
查找文件的语句
% v9 s! o* n3 J
" K ^: W2 m8 y/ j
CODE:
1 Z6 U" v, x$ @" e; P
/ t8 k: k7 T! J4 d9 s- v) \) R0 J
drop table tmp;
* Q8 r+ ~9 H8 V* c2 `& E
create table tmp
1 q. a( T1 s9 Q0 h3 m
(
) \ `) A3 j$ h2 E
[id] [int] IDENTITY (1,1) NOT NULL,
9 C' v# q! h% Z" X& P
[name] [nvarchar] (300) NOT NULL,
5 K) E/ K. e1 b$ y, B" i
[depth] [int] NOT NULL,
- t$ T0 V: e: o( B# C1 v' m+ d
[isfile] [nvarchar] (50) NULL
5 S. ?" n6 r b, {7 r, b: d5 K+ W
);
, s; s) i, Q7 B- H* t( l
- x) F$ P' o9 L# ?' N
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
2 M: I1 D. N$ Y, H5 s5 i
set @root='f:\usr\' -- Start root
1 `- x& _* q' `, _& i1 C
set @name='cmd.exe' -- Find file
8 ^9 r8 t y. ~! J, j. m# C
insert into tmp exec master..xp_dirtree @root,0,1--
& \7 u# p7 F1 y+ w+ _! X
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
( u" ~8 i# J* S4 N/ g+ O1 l0 \
set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
G) N6 O6 s& ^/ p/ K m: C
while @depth<>1
9 V5 l' `) \* D0 q7 }1 r4 z! O
begin
- d6 s8 }7 B. W' O! X* l8 `
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
' ~, i# t4 l( G8 T; R u( _
set @depth=(select depth from tmp where id=@id)
% _6 q- h& H$ o1 ?/ O$ A2 T
set @name=(select name from tmp where id=@id)+'\'+@name
& x' f8 l7 P% w
end
( \2 m- }# A( B$ u5 h. W
update tmp set name=@root+@name where id=1
1 X5 \8 U/ T2 j$ O( E5 Y
select name from tmp where id=1
& K, t, E7 I2 }4 i( ~% q
}( s, p+ |# K6 F1 X; T/ _ x
查找目录的语句
3 V6 e c* R- V: d5 r) j3 a2 G
{2 p- H1 C( x1 p4 g* F+ o: x
# @/ t+ X$ G, K) h3 |4 n
CODE:
# [2 \4 F1 {( _9 s
6 Z; q# J2 X5 c2 J
7 K; Z5 v8 e$ M. E8 ?" D: @* h% d+ u$ |
drop table tmp;
" ?# Y4 f, E1 t$ F# _
create table tmp
, U! E& j- d& \5 A: R# t! A$ l
(
# a" Q% ~9 C8 L7 ~9 t
[id] [int] IDENTITY (1,1) NOT NULL,
2 c( i& \* G# Y" x' A
[name] [nvarchar] (300) NOT NULL,
+ T! m5 }" T' b5 ^0 p, l( M
[depth] [int] NOT NULL
1 m" P* a& p8 ]. `* w' a8 D
);
# d+ y) V0 v; g
* p Q- P0 _" W3 e
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
& \; @" O1 X) V& W# g
set @root='f:\usr\' -- Start root
6 F% b+ D) a# u
set @name='donggeer' -- directory to find
6 Y5 J% b; r7 M5 H
insert into tmp exec master..xp_dirtree @root,0,0
4 `" O) S3 ^- Q$ z y+ P' _' o) X
set @id=(select top 1 id from tmp where name=@name)
O* C4 ~0 M. W$ n4 x. f- S
set @depth=(select top 1 depth from tmp where name=@name)
7 C7 N3 t" Y" Z N/ [$ M
while @depth<>1
3 M5 C0 m3 f7 {
begin
5 N$ J4 P" X1 O7 j8 E. E% C% x
set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
6 @) c$ x2 h5 s+ m; q9 @ M; n* V
set @depth=(select depth from tmp where id=@id)
4 `+ G3 W, D6 } X/ D4 v% K
set @name=(select name from tmp where id=@id)+'\'+@name
9 M6 z! K! y; _
end update tmp set name=@root+@name where id=1
5 o2 z7 E" N' \6 j2 G
select name from tmp where id=1
欢迎光临 中国网络渗透测试联盟 (https://cobjon.com/)
Powered by Discuz! X3.2