Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use command line to zip and Unzip

Status
Not open for further replies.

123ASP

MIS
Nov 2, 2002
239
US
Hi, this is a code when I execute it from sql server query window , it runs. Does anyone knows how I can reverse the function so instead of zipping the files I need to unzip them into a new folder.....

thanks for your help and support

Al

declare @varcmd varchar(255), @CurrentDate char(50),@OldDate char(50),
@txtfilename varchar(30),
@CurrentZipFilename varchar(50),
@CurrentZipFilename_old varchar(50)
Select @CurrentDate = convert(char(50),getdate(),112)
Select @OldDate = convert(char(50),getdate()-1,112)
select @CurrentZipFilename = 'xyz' +'_'+ substring(@CurrentDate,1,8)+'.zip'
select @CurrentZipFilename_old = 'xyz' +'_'+ substring(@OldDate,1,8)+'.zip'

select @CurrentZipFilename as Current_zipedfile,@CurrentZipFilename_old as Old_zipedFile ,@CurrentDate as CurrentDate,@OldDate as OldDate

-- extract data from table to out folder by executing the following sp
--execute p_BCP_out_cursor
select @varcmd =null
select @varcmd = 'C:\Batch_code\zip -j C:\OUT\'+@CurrentZipFilename+' C:\OUT\*.*'
exec master..xp_cmdshell @varcmd

Print '***************move the zip file to C:\OUT_TRANSIT\ *********'
select @varcmd = null
/*this is the text file need to be zipped,copy and past into diff dir no date addedto file name */
select @varcmd = 'move C:\OUT\'+@CurrentZipFilename+' C:\OUT_TRANSIT\'
exec master..xp_cmdshell @varcmd
 
I am not sure about ZIP, but WINRAR has to modules for shell command: rar.exe(to compress) and unrar.exe(to uncompress).
Both has parameters to specify where to
(un)compress and many others. By my knowledge, winrar is able to (un)compress zip files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top