Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo
I've been searching and reading within this forum to be able to get 7-zip to perform these actions for me but haven't been able to get this to work. I have been using the GUI version but read that my tasks could be completed easier using the command line version. I'm trying to create a batch file to drop into a folder, double click it and have all files in that folder be created into a separate .7z file. I've created this command line for 7-zip but can't even get this to work:
for /D %%A in (*) do "c:\program files\7-Zip\7z.exe" a -t7z -m9=LZMA2 -md=256m "%%A.7z" "%%A"
If it doesn't make sense, this is what setting I'm trying to create:
Keeping the same file name within the same directory
Can anybody help me to create a batch file with the above parameters so that I could just drop the batch file in the folder and double click it so that 7-zip starts compressing the files one by one? Thanks
I still can't seem to get it to work, comes back "The syntax of the command is incorrect". This is what I'm typing in the command line under the folder I want to compress:
for /D %A in (*) do "c:\program files\7-Zip\7z.exe" a -t7z -mx9 -m0=lzma2:d256m "%A.7z" "%A"
and this is the contents of my batch file:
for /D %%A in (*) do "c:\program files\7-Zip\7z.exe" a -t7z -mx9 -m0=lzma2:d256m "%%A.7z" "%%A"
Why do you use FOR/D when you do not want to work on Directory names?
I really only have a limited understanding of what the command line is saying. What should I use instead?
FOR %%A IN (*) DO "c:\program files\7-zip\7z.exe" a -mx9 -m0=lzma2:d256m "%%~nA.7z" "%%A"
Thank you so much, works like a charm. Just a quick concern, in the command prompt during compression, it states:
DEL: WARNING: The system cannot find the file specified
Compress.7z: WARNING: The system cannot find the file specified.
It repeats it during each file compress action. It still compresses everything in the folder, don't know what this warnings mean tho. Thanks!
is a separate line and used in a batch script only; not from a command line.
You indicated that the batch script would be placed in the same directory in which it would be executed.
The script will archive ALL files, including batchFileName.bat.
That DEL line translates to DELete batchFileName.7z
If there are two files - for example fileName.DAT and fileName.TXT, the both will be archived in fileName.7z
If you would prefer fileName.DAT => fileName.DAT.7z and fileName.TXT => fileName.TXT,.7z
change the "%%~nA.7z" to "%%A.7z"
"%%~nA" == filename of %%A without the .EXTension
I removed the line from the batch file and everything is working perfectly. Thanks so much for your help.
I stumbled upon this thread and it was a GREAT help to me! Thank you all for making this community awesome!
I do have one question…
How would I change the command to make it so instead of files, it was folders that got turned into 7z archives?
For example, if I want to put a batch file in a folder, and then have each folder IN that folder created into separate 7z archives - how would I write that in the CMD?
Apologies…I figured it out. Total brain glitch on my part.
I misread the opening few posts - the answer was there for me :)
For /D %%A in (*) do "c:\program files\7-Zip\7z.exe" a -t7z -mx9 -m0=lzma2:d256m "%%A.7z" "%%A"
Worked like a charm!
Sorry, but I was wrong. It's not working.
The command itself seems to work but for some reason it ignores folders. I place the batch file in a folder, where there are 15 folders I want archived to 7z. It stops after 9 folders. Just ignores the others. Why is this? How would I fix it?
Please help, thank you!
I found out that it's due to something related to the dictionary and word values. If I lowered them both to 64m (vs. 256m) - the folders work fine - all of them.
Why would a higher dictionary and / or word values cause this batch file to skip folders or just plain not execute?
super thanks…. !!! this 1 line based on @ikxcsshcm7 's reply saved our skins. We encrypted all files in the containing folder with pass-word as the filenames themselves and wrote another script to update the filenames.
FOR %%A IN (*) DO "c:\program files\7-zip\7z.exe" a -p"%%~nA" -tzip "%%~nA.zip" "%%A"