0

i am trying to run a batch file that extracts only .jar files with 7z.exe
here is my code:

set location=%cd%
set filename=%location%\outputfolder
set unzip=%location\resources

cd %unzip%
7z e -o%filename% -ir!*.jar -y "%filename%\*.zip"

but it gives an exception: error: incorrect command line so i removed the -ir!*.jar and it then gives another error: error: cannot use absolute pathnames for this command so i changed the -o%filename% to -oC:\outputfolder and it works!!!!!!(here is my script now):

set location=%cd%
set filename=%location%\outputfolder
set unzip=%location\resources

cd %unzip%
7z e -oC:\outputfolder -y "%filename%\*.zip"

but i need these features
how fix?

user2669763
  • 19
  • 1
  • 3

1 Answers1

1

try it with double quotes, %cd% maybe has spaces:

7z e -o"%filename%" -i!*.jar -y "%filename%\*.zip"

Usage from the help screen:

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Usage: 7za  [...]  [...]
       []


  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths

  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -v{Size}[b|k|m|g]: Create volumes
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries

enter image description here

Endoro
  • 37,015
  • 8
  • 50
  • 63
  • @user2669763 I tested it, works fine here. I added the Help screen to my answer. – Endoro Aug 21 '13 at 21:24
  • can you tell me what this is? `SETLOCAL ENABLEDELAYEDEXPANSION` this is what is stopping 7zip from running! is there any way to unset it? – user2669763 Aug 23 '13 at 01:33
  • I can't see any `setlocal` in your code. `Delayed expansion` is necessary to access variables in `if` and `for` code blocks. – Endoro Aug 23 '13 at 03:36
  • [check this out](http://stackoverflow.com/questions/18422082/setlocal-enabledelayedexpansion-interrupt-setlocal-enabledelayedexpansion-set) – user2669763 Aug 24 '13 at 19:23