中国网络渗透测试联盟

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

作者: admin    时间: 2012-9-15 14:42
标题: 快速度查找文件和目录的SQL语句
查找文件的语句
2 g& i9 r7 w0 l1 W! F  ^, u# r$ U) E9 [- M- X
CODE:
# Q( y8 F  x4 X4 b! n7 Z+ {- G- r: w/ c4 D
drop table tmp;0 d6 k* z+ ~( A
create table tmp
, J: O  l, S; D7 ^(
7 F9 p( B( B) h4 y: r9 @5 K[id] [int] IDENTITY (1,1) NOT NULL,1 @9 @2 N& v4 J" V& \4 u' o+ h
[name] [nvarchar] (300) NOT NULL,0 L& v7 q& b! g7 z# u- A0 {
[depth] [int] NOT NULL,7 P. n6 J; e+ a8 \0 b% O9 V( w% C- x
[isfile] [nvarchar] (50) NULL
$ w) N6 C( C3 [" g6 I) B/ ?);
" n" }8 T5 E- ]$ X2 R# d4 ^+ w
/ [1 ^  p( E8 T9 e3 o. Gdeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
" T6 I" s9 R4 V# ~$ cset @root='f:\usr\' -- Start root
( q; n: i& P7 W$ n6 A: Z# ]& Hset @name='cmd.exe'   -- Find file) u8 X' Q- F* y" d7 R8 @
insert into tmp exec master..xp_dirtree @root,0,1--
9 \# F. S+ ^5 Y) e4 q. i& Bset @id=(select top 1 id from tmp where isfile=1 and name=@name)
0 V& `2 h' A6 O* J: ~set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
. z$ r4 `. c, T3 s' k1 v+ h! Wwhile @depth<>1
% C" Z& c( w  D0 Cbegin 2 v8 l0 L3 [+ o$ p$ r% K
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc) % i- N* a- q6 {
set @depth=(select depth from tmp where id=@id)
8 R& u2 P. T1 M- I& @set @name=(select name from tmp where id=@id)+'\'+@name
" y- T5 Q+ Q4 ^0 A2 L* ?7 Oend
/ j9 s9 U; ~& z* U5 cupdate tmp set name=@root+@name where id=1
0 r  t& k) \. Y- Q$ m2 c3 Fselect name from tmp where id=1. P6 B6 S4 y! G, ~! `7 A( d7 T

9 h; P) l/ E$ [9 H  q. m: R3 i查找目录的语句
- O; M' Z$ k; H
) b5 W9 p3 A; l8 j! O$ b
3 v3 Z5 l; S- T- k0 z4 ECODE:
& H6 c  x6 N/ G0 w! J6 _1 a2 |" g% a! a. `- w

  m: q8 }& _# @  I& C6 ]' k+ cdrop table tmp;
8 f2 z! C( K6 a% ocreate table tmp
, u' e7 w6 m( L. u6 S+ N7 R& e(0 X4 e- R# y8 z( R; V' B
[id] [int] IDENTITY (1,1) NOT NULL,
5 S) u; w2 d, s3 b7 b' y[name] [nvarchar] (300) NOT NULL,7 }( P8 ^' f$ M3 t
[depth] [int] NOT NULL
3 o9 S! x/ i8 U0 ]4 [7 F0 w);% c, n; Y" [9 z/ {

- y- d$ B' j: m. z* T  ^  K% edeclare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
6 |- g8 H) O6 w6 p' e9 Bset @root='f:\usr\' -- Start root
# @& s: {8 S- c. m  Mset @name='donggeer' -- directory to find5 ~% I1 c9 i" y
insert into tmp exec master..xp_dirtree @root,0,0
" V* P+ T6 X1 v7 e6 b. ^% vset @id=(select top 1 id from tmp where name=@name)
( a) v' B" m2 Fset @depth=(select top 1 depth from tmp where name=@name) 6 R- t8 p  r& L+ u' D, k2 w
while @depth<>1 : l: P7 M$ Z4 _4 E& c/ b/ a; g. S; Q
begin
5 F6 t: V- Q" N0 U& C+ Dset @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)* L2 M$ A5 v' [+ I& d  R% i
set @depth=(select depth from tmp where id=@id) $ |' }! x# F% X3 u; q  Q5 G* m
set @name=(select name from tmp where id=@id)+'\'+@name . x9 b0 F' r& h2 m: h
end update tmp set name=@root+@name where id=1
- q  {+ E2 B0 ]6 K( Lselect name from tmp where id=1




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