查找文件的语句
4 b G; j$ c3 }$ l9 l" p& v9 H" R: v( `" D/ r1 z% I
CODE:7 H$ K; z5 J' i
6 O* s4 j% F% O+ T% jdrop table tmp;! K3 E% h; v+ n
create table tmp
) i" {8 K9 R3 D8 d/ l/ A0 y5 o(& ~6 H9 x/ E! W; c; e* {3 s1 d
[id] [int] IDENTITY (1,1) NOT NULL,
4 v" h" w* P, O, Q* H' P% B[name] [nvarchar] (300) NOT NULL,& p5 a0 q6 P- i1 ^
[depth] [int] NOT NULL,
8 J7 N4 U" C! E5 t& g[isfile] [nvarchar] (50) NULL( d' x) Z4 y8 g, n# |
);; n* B8 Z7 c/ S8 S2 H& b# X" W
2 i$ N+ W# d4 T
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
; d. y2 |: d( S9 V4 x5 r1 Gset @root='f:\usr\' -- Start root, a8 q7 J7 t( ^$ W' e! V% r
set @name='cmd.exe' -- Find file2 w7 D& g! z+ p7 X! B) v( w
insert into tmp exec master..xp_dirtree @root,0,1--" T2 S$ k4 B/ L
set @id=(select top 1 id from tmp where isfile=1 and name=@name) 7 f1 a9 J' Y+ O! ]$ f
set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
9 d2 H9 G! d9 d0 }while @depth<>1
' _" R* ]/ ?$ l/ u' U+ ybegin
1 d. D3 W. T8 M v2 b( V- sset @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc) * d7 n8 ], z$ ]! M) A# {1 y k
set @depth=(select depth from tmp where id=@id)
8 _$ a4 F" Q4 v1 K0 m8 o: r4 `set @name=(select name from tmp where id=@id)+'\'+@name
- {- Z) \. h. ]: Nend2 w# K' W$ q# W0 D E& ?. N1 v' r$ w
update tmp set name=@root+@name where id=1
. e& j( }, f2 x) x% y$ E6 M }select name from tmp where id=1; D$ o$ }4 a, o; b
, k0 {/ X6 ^ q0 q) u+ j# T查找目录的语句8 S& r" X; S( b& g
# `) Y$ D! {3 X6 X$ B/ W, f Q1 \. B* j7 M
CODE:2 }9 r, ?& v8 F0 M3 l* l
( X; e y+ C; E4 m6 S. U/ S
" U5 ?, p8 v: Vdrop table tmp;
4 h4 {" y" n* m& k4 Wcreate table tmp; a: D7 T' O- i" L5 T1 |
(
; O$ k! j2 z" L& O/ W! J[id] [int] IDENTITY (1,1) NOT NULL,! J6 h: ^) g, F3 a- l1 J& t- ]
[name] [nvarchar] (300) NOT NULL,
3 b- f( W7 [) Q6 Z4 Y# {/ D# U[depth] [int] NOT NULL
9 j5 f3 |) G7 a);8 G y7 u$ b7 N1 u, Y) ]
& I, [/ m$ k* W7 z# c9 i2 b/ p
declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)3 s8 Y6 @: _$ q% T' j) U
set @root='f:\usr\' -- Start root, B3 F- O* W) b+ W2 o
set @name='donggeer' -- directory to find O6 Y4 A$ f$ E
insert into tmp exec master..xp_dirtree @root,0,0
4 Y. j# J5 |! P" pset @id=(select top 1 id from tmp where name=@name) + U r4 m. y# A1 S9 O+ p0 ^
set @depth=(select top 1 depth from tmp where name=@name)
9 i3 H, A3 L5 R. H/ `7 J& P& iwhile @depth<>1 / c* r& U3 G/ p8 E& M% Q+ v' D
begin
9 {! k# B) R; `) }. aset @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)* C! c$ K. D5 }9 X6 Z
set @depth=(select depth from tmp where id=@id) ' u! j+ g0 v- K, F
set @name=(select name from tmp where id=@id)+'\'+@name
4 m5 w# N5 U1 h x: Vend update tmp set name=@root+@name where id=1
" T3 \( j! }8 \. i; g, w: ?select name from tmp where id=1 |