extracting jar files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sanjayk
Posts: 4
Joined: 05 Dec 2012 11:33

extracting jar files

#1 Post by sanjayk » 05 Dec 2012 11:46

Hi,

I want to create a batch script which can extract all the jar files existing in a given folder and extracted files are placed in the given folder. Both the paths (source jar files folder and extracted files folder) will be asked by the script when we run the script.

I tried to first take the path from user and extracting files in the same folder but it did't work....
---------------------Batch Script--------------------------------------
@echo off
set /p pathsource= Enter the path where jar files are kept :
echo Source path is %pathsource%.
cd %pathsource%
for /r %pathsource% %i in (*.jar) do jar -xvf %~nxi
echo stop here.
pause
-----------------------------------------------------------------------

Can anyone please help me ?

Thanks
Sanjay

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: extracting jar files

#2 Post by foxidrive » 05 Dec 2012 12:11

Try this:

Code: Select all

@echo off
set /p "pathsource= Enter the path where jar files are kept: "
echo Source path is "%pathsource%"
cd /d "%pathsource%" && (
for %%a in (*.jar) do jar -xvf "%%a"
)
echo stop here (or incorrect path)
pause


sanjayk
Posts: 4
Joined: 05 Dec 2012 11:33

Re: extracting jar files

#3 Post by sanjayk » 05 Dec 2012 21:39

Thanks fox and bill :) both Scripts are working fine .........
Can we also provide the destination folder where extracted files will be placed(not in source jar files folder)?

sanjayk
Posts: 4
Joined: 05 Dec 2012 11:33

Re: extracting jar files

#4 Post by sanjayk » 06 Dec 2012 00:29

Even if we provide destination path in the script, how to write the final script.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: extracting jar files

#5 Post by foxidrive » 06 Dec 2012 01:09

This might work (untested:)

Code: Select all

@echo off
:loop
set /p "pathsource= Enter the path where jar files are kept: "
set /p "pathtarget= Enter the path to extract jar files to: "
echo Source path is "%pathsource%"
echo Target path is "%pathtarget%"
if not exist "%pathsource%\" goto :loop
if not exist "%pathtarget%\" goto :loop
cd /d "%pathtarget%"
for %%a in ("%pathsource%\*.jar") do jar -xvf "%%a"
echo stop here
pause

sanjayk
Posts: 4
Joined: 05 Dec 2012 11:33

Re: extracting jar files

#6 Post by sanjayk » 06 Dec 2012 01:58

It's working fine..... Thanks a lot fox :D

Post Reply