--Compress all files in one directory into another --Extract the compressed file to the original directory
At the time of powershell, I used 7zip to operate from the command line, but I wondered if there was anything else When I looked it up, there was something very useful
-** shutil
** is used as import
--Compression: ** `shutil.make_archive``` ** [compression destination path], [format], [path of the directory you want to compress] -** Extension is not included in [** compression destination path **] ** --Unzip: **
`shutil.unpack_archive``` ** [path you want to unzip], [destination]
-** Add the extension to [** Path you want to unzip **] **
compression
import shutil
#Compression destination
done_dir = 'C:/test/done/testzip'
#Directory of files you want to compress
output_dir = 'C:/test/output/'
z = done_dir
r = output_dir
#compression
shutil.make_archive(z, 'zip', root_dir=r)
Defrost
#Compressed file you want to decompress
zf = f'{z}.zip'
#Defrost
shutil.unpack_archive(zf, extract_dir=output_dir)
Recommended Posts