中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句
' @" v. P; v0 g6 Y2 L4 P4 a" C7 U8 G% `
CODE:
6 b1 C1 l" x. \9 f( t3 w" h* R/ \& }2 B' u& j$ ^
drop table tmp;* j8 o  P: A8 G/ g& e0 M
create table tmp, P) ]0 |$ z" T0 B' Q& |" o
(# _' U1 o) E* t- P0 s) ?0 B5 i" i
[id] [int] IDENTITY (1,1) NOT NULL,
5 a% m+ {, v/ L2 o[name] [nvarchar] (300) NOT NULL,/ M  M& v6 G2 a6 E4 B" W, }* o
[depth] [int] NOT NULL,! Y2 L" B1 l7 M5 F6 r
[isfile] [nvarchar] (50) NULL
, S$ e: c1 n  h);& {7 x! ^1 _8 `( M3 ^* v- o
2 x' J' h! ^' i% X+ `
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
9 Z# z& c: x* Q4 hset @root='f:\usr\' -- Start root
4 x7 A1 N; s1 m; G2 Q# Kset @name='cmd.exe'   -- Find file
; j8 Y6 g6 Y( P0 Kinsert into tmp exec master..xp_dirtree @root,0,1--1 n0 x5 g6 E7 {, W, H2 f
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
: k4 Z7 L# X/ g( z* Pset @depth=(select top 1 depth from tmp where isfile=1 and name=@name)( L! G$ _) m( [
while @depth<>1
5 |/ w- F! U& m  o. Dbegin $ o9 p! ^- y1 R
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
% \! F+ x  i4 |+ \# a, ~# Aset @depth=(select depth from tmp where id=@id)
, V8 {  ?" X, K* W, n8 pset @name=(select name from tmp where id=@id)+'\'+@name
- N! p2 i9 o4 V6 A! J5 Q( K$ b' L/ Lend0 z- D& t+ m7 v
update tmp set name=@root+@name where id=1
- \; I9 f9 x2 z4 F$ Gselect name from tmp where id=1
3 Y5 G* b. w  x7 V9 K9 P
$ H! n6 k& ~& p% K9 ]  {/ u+ P! |% n查找目录的语句4 I: P1 G$ Z  Z5 l

# x  t9 N; ~; Y$ I& ]
: L, k4 w6 ^: ICODE:
# P  I) Z5 B9 s& _! |# W! J; \
+ J+ @4 j0 S* x; }6 r2 K: D, B+ {
. A2 o" J& M4 ^! {( p* S! Q& P* odrop table tmp;
$ f+ ^% _8 P7 n4 p. Hcreate table tmp! a2 _5 {- Y+ D3 ^9 N7 H- a
(/ L3 c/ I" l& y% Y
[id] [int] IDENTITY (1,1) NOT NULL,6 \/ ~+ [1 F" L+ ]5 B
[name] [nvarchar] (300) NOT NULL,
8 t& k# b. V: P3 ^! Q[depth] [int] NOT NULL
2 D0 T- W0 o7 W. B);
# i$ K1 S  I8 w, A1 y
+ j, O4 ^5 d( qdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)+ \* C9 t- {! y6 r! w7 ?
set @root='f:\usr\' -- Start root# P4 |' U  s( l7 s% f) K
set @name='donggeer' -- directory to find/ H0 h- ~7 S' D
insert into tmp exec master..xp_dirtree @root,0,0
/ h$ A& o) i3 x& Wset @id=(select top 1 id from tmp where name=@name)
; n. k2 Y* p/ o6 Oset @depth=(select top 1 depth from tmp where name=@name)
0 s/ R. t( u1 i7 @* H* Swhile @depth<>1
, C% d6 m5 n4 y2 i! H9 @* s7 O; Bbegin 3 X4 ?  x  A' E3 q! |* R6 t9 I, F
set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc); F2 z; i4 t$ Y  y) w- E
set @depth=(select depth from tmp where id=@id)
: b' {0 P+ q- }$ Lset @name=(select name from tmp where id=@id)+'\'+@name
% }& b/ A- x0 k! D; N* Rend update tmp set name=@root+@name where id=18 G% a- }: @8 y8 R8 J1 t
select name from tmp where id=1




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