SQL利用CMD及RAR命令实现将某一压缩文件解压到指定的路径

这篇博客介绍了一个SQL存储过程,通过CMD和RAR命令来解压RAR文件到目标路径。首先需要将RAR和UNRAR工具放在system32目录下,然后创建的存储过程会检查文件是否存在,解压文件,并根据参数决定是否覆盖子目录。最后,存储过程还会删除解压后的临时目录。
摘要由CSDN通过智能技术生成
--说明:首先要将RAR以及UNRAR复制到system32下,或者设计环境变量
/*
declare @t nvarchar(256)
EXEC p_cmd_unrar_copy 'D:\xxxx.rar','D:',@t output
select @t
*/
Create proc p_cmd_unrar_copy
(
@fullfilepath nvarchar(256),--要解压的RAR文件
@tofilepath nvarchar(256),--要复制到的文件夹(不加\)
@filetime nvarchar(256) output,--输出解压的文件夹的时间及大小以及文件名,不截取时间了
@iscopychildCover bit=1--是否复制子目录并覆盖
)
as
set nocount on
declare @isok int,@childfile nvarchar(256)
set @isok=-1;
if isnull(@fullfilepath,'')='' or isnull(@tofilepath,'')=''
begin
	select '输入不正确'
	return @isok;
end
else
begin
		declare @r int 
		exec master..xp_fileexist @fullfilepath,@r output
		if @r=0
		begin
				select @fullfilepath+'文件不存在!'
				return @isok
		end
		
		if OBJECT_ID('tempdb..#tofilepath') is not null
		drop table #tofilepath
		create table #tofilepath(col nvar
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值