国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

如何在SQL SERVER 2000中刪除系統文件?

2024-08-31 00:48:19
字體:
來源:轉載
供稿:網友


    /*****************************************************************************************************************

      在sql server 2000的開發過程中有時會遇到要判斷和刪除系統級別的一些文件,這是通過sql server2000提供的一些系統函數可以非常方便的完成相應的功能.下面是我寫的一個實列:

author:黃山光明頂

mail:[email protected]

version:1.0.0

date:2004-1-30

(如需轉載,請注明出處!)

*********************************************************************************************************/
if exists (select * from sysobjects where id =
object_id('dbo.usp_deletefile') and sysstat & 0xf = 4)
 drop procedure usp_deletefile
go
create procedure usp_deletefile
 @filename varchar(255),
 @path     varchar(1024)
as
begin


 declare @rc   int
 declare @space_num int
 declare @debug  int
 declare @temppath varchar(1024)
 declare @tempdel varchar(1024)

 select @rc=0
 select @space_num=0

 select @debug=0

 select @temppath=''
 select @tempdel=''
 set nocount on


/***************************************************************************
***********
  * check whether @filename is null

****************************************************************************
**********/
 if  @filename is null
 begin
  print 'please input file name'
  select @rc=-90001
  return @rc
 end


/***************************************************************************
***********
  * check whether @path is null

****************************************************************************
**********/
 if  @path is null
 begin
  print 'please input delete file directory(exclude space)'
  select @rc=-90002
  return @rc
 end


/***************************************************************************
***********
  * check whether @path  includes space
  * if the os is windows 2000 ,please confirm the path not includes space!!

****************************************************************************
**********/
 select @space_num=charindex(' ',@path)
 if  @space_num>0
 begin
  while charindex(' ',@path)>0
  begin
   select @[email protected]+left(@path,charindex(' ',@path))
   select @path=ltrim(right(@path,len(@path)-charindex(' ',@path)))
  end

  select @[email protected][email protected]
  select
@temppath=stuff(replace(@temppath,'/','"/"')+'"',1,3,left(@temppath,2))+'/'+
@filename

  if @debug=1
  begin
   print @temppath
  end


 end

 select @[email protected]+'/'[email protected]

 if @debug=1
  begin
   print @temppath
  end


/***************************************************************************
***********
  * create temp table to records file information

****************************************************************************
**********/
 create table #fileexists(doesexist smallint,fileindir smallint,direxist
smallint)
 if @rc=0
 begin

  insert into #fileexists exec master..xp_fileexist @temppath
  if exists (select 1 from #fileexists where #fileexists.doesexist=1)
   begin
    select @tempdel='del '[email protected]
     if @debug=1
      begin
       print @tempdel
      end
    exec  @rc=master..xp_cmdshell @tempdel,no_output
    if @rc<>0
     begin
         print 'deleting file faile,may be file in useing!'
         drop table #fileexists
         select @rc=-90003
         return @rc
     end
    else
     begin
         print 'deleting file sucessfully!'
     end

   end
  else
   begin
    print 'please check the directory and filename.the input file not
exist!'
   end

 end

        drop table #fileexists
 return @rc
end
go
exec usp_deletefile 'test.txt','c:/temp'


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绥宁县| 德江县| 浙江省| 澄城县| 黄龙县| 武鸣县| 监利县| 鹤峰县| 平果县| 桐柏县| 罗江县| 长沙县| 任丘市| 中卫市| 正阳县| 牡丹江市| 龙井市| 山阳县| 天柱县| 西乌珠穆沁旗| 道真| 康保县| 滨州市| 双牌县| 通榆县| 共和县| 鞍山市| 定边县| 寻乌县| 哈尔滨市| 平顺县| 神农架林区| 天峨县| 天门市| 齐齐哈尔市| 甘德县| 江门市| 兴山县| 阳城县| 泾阳县| 遂溪县|