I have a code that compress every file in a specific folder with zip but I want to compress it with 7zip, so how to do ?
This is what I have so far:
for date in dict_date:#zipping folders and get same name like the folder
with ZipFile(os.path.join(src, '{0}.7z'.format(date)), 'w') as myzip:
for subFolder in dict_date[date]:
for fil in os.listdir(os.path.join(src, date, subFolder)):
if not fil.endswith('.7z'):
myzip.write(os.path.join(src, date, subFolder, fil))
Archive format — lets you choose the file's format. For the best compression rate, choose 7z. Compression level — the compression time increases with the compression level.
Open the folder containing the files you want to zip, right-click on any free space inside the folder, choose New and then Compressed (zipped) Folder. Name the archive as you wish. Double-click on the newly created archive: a new window will open. Drag and drop any file you want to archive into this folder.
Press Win+I to open Settings, and click on Apps. On the left panel, click on Default apps. Then, scroll down on the right panel and click on Set defaults by file type. Here, you can individually select the file types that you want to open with 7zip File Manager by default.
Again, if you create Zip files and see files that cannot be significantly compressed, it is probably because they already contain compressed data or they are encrypted. If you would like to share a file or some files that do not compress well, you might: Email photos by zipping and resizing them.
You can try the command line method
import subprocess
subprocess.call(['7z', 'a', filename+'.7z', filename])
or for all files in folder
subprocess.call(['7z', 'a', filename+'.7z', "*.*"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With