create
proc
p_QueryCheckFile
@path nvarchar ( 1000 ),
@fname nvarchar ( 250 )
as
-- 检查文件是否已经存在
if right ( @path , 1 ) <> ' \ '
set @path = @path + ' \ '
if exists ( select *
from sysobjects
where type = ' u '
and
name = ' temp_xp_fileexist ' )
begin
drop table temp_xp_fileexist
end
create table temp_xp_fileexist(a bit ,b bit ,c bit )
declare @sql nvarchar ( 1000 )
set @sql = @path + @fname
insert into temp_xp_fileexist
exec master..xp_fileexist @sql
/*
xp_fileexist 返回的三个列, 分别代表
文件已存在 文件是目录 父目录已存在
----- ----- ------
0 0 1
*/
if exists ( select 1 from temp_xp_fileexist where a = 1 )
-- 文件已经存在
begin
declare @del nvarchar ( 200 )
select @del = ' del ' + @sql
exec master..xp_cmdshell @del
end
GO
@path nvarchar ( 1000 ),
@fname nvarchar ( 250 )
as
-- 检查文件是否已经存在
if right ( @path , 1 ) <> ' \ '
set @path = @path + ' \ '
if exists ( select *
from sysobjects
where type = ' u '
and
name = ' temp_xp_fileexist ' )
begin
drop table temp_xp_fileexist
end
create table temp_xp_fileexist(a bit ,b bit ,c bit )
declare @sql nvarchar ( 1000 )
set @sql = @path + @fname
insert into temp_xp_fileexist
exec master..xp_fileexist @sql
/*
xp_fileexist 返回的三个列, 分别代表
文件已存在 文件是目录 父目录已存在
----- ----- ------
0 0 1
*/
if exists ( select 1 from temp_xp_fileexist where a = 1 )
-- 文件已经存在
begin
declare @del nvarchar ( 200 )
select @del = ' del ' + @sql
exec master..xp_cmdshell @del
end
GO