Author Topic: Command line to batch 7zip a folder full of files?  (Read 14027 times)

Offline Kodoichi

  • Full Member
  • ***
  • Posts: 162
Command line to batch 7zip a folder full of files?
« on: May 01, 2010, 04:34:13 PM »
I once downloaded lots of Tosec ADF packs in 7zip format, now I'm running out of space on my harddisk and need to compress all the ADFs again.

Does anybody know how the command line syntax for 7zip is, if I want to batch compress all ADFs in a specific folder individually?  ???

So Gamename1.adf has to become Gamename1.7z, Gamename2.adf becomes Gamename2.7z...



Offline PandMonium

  • Administrator
  • Hero Member
  • *****
  • Posts: 1332
Re: Command line to batch 7zip a folder full of files?
« Reply #1 on: May 01, 2010, 08:40:21 PM »
Hi Kodoichi,

I think 7z is not able to do that by itself (winrar has an option for that for example) so you have to use a batch file to pick each file and zip it individually.
From a quick search at google i've found this: http://r3dux.org/2009/04/how-to-compress-a-directory-of-files-into-individual-archives/
The post is about bash/linux scripting but if you read the comments they also have a pretty neat solution in 2 or 3 lines for windows too. Not sure if it works because i didn't tested it.
Just save it to a .bat and try it yourself :)

Offline TKaos

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 539
Re: Command line to batch 7zip a folder full of files?
« Reply #2 on: May 01, 2010, 08:59:37 PM »
I always used clrmame for that but later decided that ZIP is better since it's faster to update archive&filenames.

Offline Kodoichi

  • Full Member
  • ***
  • Posts: 162
Re: Command line to batch 7zip a folder full of files?
« Reply #3 on: May 03, 2010, 03:51:42 PM »
I searched again and found this:
http://www.hak5.org/forums/index.php?showtopic=7117&mode=threaded&pid=74792

I shortened it to:
for %%f in (*.adf) do C:\Programme\7-zip\7z a "%%f".7z "%%f"

(Programme = program files folder)
I saved it into a folder full of ADFs to test it. Seems to work well, except that the zipped files are all still called Gamename.adf.7z instead of just Gamename.7z. Does anybody know how to get rid of the .adf extension when zipping the files?

And while I'm writing this I found this here:
http://www.autohotkey.net/~RedShadow/7zef/

That script works perfectly ;D

Offline PandMonium

  • Administrator
  • Hero Member
  • *****
  • Posts: 1332
Re: Command line to batch 7zip a folder full of files?
« Reply #4 on: May 03, 2010, 04:03:39 PM »
Good post Kodoichi,

I guess other users might find the information useful. By your last line i guess you don't need the information but anyway to get the names without the extension you use "~n", for example:
Code: [Select]
"for %f in (*.adf) do echo %~nf"will output all the adf files without the extension :P


Offline Kodoichi

  • Full Member
  • ***
  • Posts: 162
Re: Command line to batch 7zip a folder full of files?
« Reply #5 on: May 07, 2010, 07:38:54 PM »
Freed 11GB of harddisk space  ;D

Offline robertgalp

  • Newbie
  • *
  • Posts: 1
Re: Command line to batch 7zip a folder full of files?
« Reply #6 on: February 11, 2016, 06:20:48 AM »
Check this one.....7zip commands

Robert