[toc]
#python + shutil, zip zip command
@(python)
Problems encountered
A,shutil.make_archiveThe path is abnormal after unzip is decompressed
Select an appropriate compression command as required
1.1,shutil.make_archiveAfter compression, unzip is decompressed
1.2. Decompress the ZIP file unzip
Zip Decompressed using unzip with an absolute path
To remove absolute paths:
CD to the folder to be compressed using && to connect the zip compression command
os.system('cd ' + dst + ' && zip -q -r -m -o ' + 'TYLivingRoom.zip ' + The '*')
Copy the code
Basic operation
A, compressed
1.1, shutil. Make_archive
grammar
def make_archive(base_name,
format,
root_dir=None,
base_dir=None,
verbose=0,
dry_run=0,
owner=None,
group=None,
logger=None):
Copy the code
parameter
parameter | role |
---|---|
base_name | Create the target file name, including the path, minus any specific format extensions |
format | Compressed package format.” Zip, tar, bztar, or gztar |
root_dir | The root path to switch to when packing. That is, before the packaging begins, a path switch is performed to the path specified by root_dir. The default value is the current path |
base_dir | Path to start packing. That is, the command packages the path specified in base_dir, which defaults to root_dir, the current directory after the package switch. You can also specify a specific subdirectory so that packaged files contain this uniform prefix path |
owner | The default value is the current owner of the user |
group | The default value is the current group of the user |
1.2,zip
grammar
zip -r test.zip *
parameter
parameter | role |
---|---|
-q | Indicates that the compression progress is not displayed |
-r | Indicates that all subfiles in subdirectories are compressed to ZIP. This folder is more important, otherwise only the folder something is compressed, and the folder inside is not compressed |
-e | Your compressed files need to be encrypted, the terminal will prompt you to enter the password |
-m | Delete the original file after compression |
-o | Indicates that the last modification time of all compressed files is set to the current compression time |
Second, the decompression
1.1, shutil. Unpack_archive
import shutil
shutil.unpack_archive('the Python - 3.3.0. TGZ')
Copy the code
1.2, unzip
unzip -o TYLivingRoom.zip -d .
Copy the code