--说明:首先要将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 nvarchar(max))
declare @sql nvarchar(4000)--CMDSHELL不能用NVARCHAR(MAX)类型
set @sql='dir '+@tofilepath+'\'--如果只是检验是否存在可以考虑加/B 选项
--select @sql;
begin try
EXEC sp_config
SQL利用CMD及RAR命令实现将某一压缩文件解压到指定的路径
最新推荐文章于 2024-07-08 23:29:56 发布
这篇博客介绍了一个SQL存储过程,通过CMD和RAR命令来解压RAR文件到目标路径。首先需要将RAR和UNRAR工具放在system32目录下,然后创建的存储过程会检查文件是否存在,解压文件,并根据参数决定是否覆盖子目录。最后,存储过程还会删除解压后的临时目录。

最低0.47元/天 解锁文章
833

被折叠的 条评论
为什么被折叠?



