在sql中处理文件的操作

myfavorite

DECLARE   @Path   nvarchar ( 200 )
SET   @Path   =   ' C:\Inetpub\wwwroot\kaoq\txt\ '
IF   RIGHT ( @Path 1 <>   ' \ '
    
SET   @Path   =   @Path   +   ' \ '
IF   OBJECT_ID ( ' tempdb..# ' IS   NOT   NULL
    
DROP   TABLE  #
CREATE   TABLE  #
(
    id 
int   IDENTITY ,
    directory 
nvarchar ( 260 ),
    depth 
int ,
    IsFile 
bit
)
INSERT  #  EXEC  master.dbo.xp_dirtree  @path   =   @path , @depth   =   0 , @file   =   1


declare   @strPath   varchar ( 200 )
declare  cur_file  cursor   for   select   ' C:\Inetpub\wwwroot\kaoq\txt\ '   +  directory  from  #  order   by  directory
open  cur_file
fetch   next   from  cur_file  into   @strPath
while   @@fetch_status = 0  
    
begin
        
declare   @o   int , @f   int , @t   int , @ret   int
        
declare   @card8   varchar ( 1000 )
        
declare   @date8   varchar ( 1000 )
        
declare   @time8   varchar ( 1000 )


        
exec   @ret = sp_OACreate  ' Scripting.FileSystemObject ' , @o  out
        
exec   @ret = sp_oamethod  @o , ' OpenTextFile ' , @f  out, @strPath , 1
        
exec   @ret = sp_oamethod  @f , ' readline ' , @card8  out
        
exec   @ret = sp_oamethod  @f , ' readline ' , @date8  out
        
exec   @ret = sp_oamethod  @f , ' readline ' , @time8  out
        
-- '''''''处理数据
         exec   @ret = sp_OADestroy  @f
        
exec   @ret = sp_OAMethod  @o ' DeleteFile ' NULL @strPath
        
exec   @ret   =  sp_OADestroy  @o

        
fetch   next   from  cur_file  into   @strpath
    
end
close  cur_file
deallocate  cur_file

转载于:https://www.cnblogs.com/MyFavorite/archive/2007/10/13/923003.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值