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


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
  • 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
  • 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
  • this is the folder version instead of files. mx9 is max compression. ms is solid archive. – jiggunjer Dec 1 '17 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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