Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of files in a directory and want to 7zip each one into its own 7zip archive

So, for example, 1.csv, 2.csv, 3.csv will end up as 1.7z, 2.7z, 3.7z

Is this possible with a .bat file in Windows 7? I'm using 7zip 9.29 alpha

share|improve this question

2 Answers 2

up vote 2 down vote accepted

This should do what you want (well, almost, 1.csv will be 1.csv.7z):

for %f in (*.csv) do "c:\program files\7-zip\7z.exe" a -t7z %f.7z %f

If you run this in a batch file you need to change %f to %%f.

Also, if the files 1.csv.7z already exist in the directory, you need to delete them first. The following command line should do that:

for %f in (*.csv) do del %f.csv
share|improve this answer
    
beautiful. needed a slight tweak (for named files, I'd like to keep it as generic as possible so others can use it), but i got it working ------------------ for %%f in (*.csv) do "c:\program files\7-zip\7z.exe" a -t7z "%%f.7z" "%%f" –  warsong Sep 20 '12 at 14:47
for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\" -mx=9 -ms=on -md=26 -mfb=256
share|improve this answer
    
care to explain what it does? –  Baarn Sep 20 '12 at 14:50
    
thanks, this one is even nicer, much neater output :) edit: oh erm oops. i think you got the wrong end of the stick, but good effort. –  warsong Sep 20 '12 at 14:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.