With regard to the processing of documents, there is a very important task is the compression and decompression of files.
How is python implemented?
The code:
Unzip folder:
‘‘‘
Unzip the configured folder
: return:
‘‘‘
Dirpath = "Extracted target path"
filepath = "Compressed file required for decompression"
If not os.path.exists (Dirpath):
Os.mkdir (Dirpath)
Zfobj = ZipFile. ZipFile (filepath)
For name in Zfobj.namelist ():
Name = Name.replace (' \ \ ', '/')
If Name.endswith ('/'):
p = os.path.join (Config.dirpath, name[:-1])
If Os.path.exists (p):
# If a folder exists, delete it: Avoid new updates that cannot be copied
Shutil.rmtree (P)
Os.mkdir (P)
Else
Ext_filename = Os.path.join (Config.dirpath, name)
Ext_dir = Os.path.dirname (ext_filename)
If not os.path.exists (Ext_dir):
Os.mkdir (Ext_dir)
outfile = open (Ext_filename, ' WB ')
Outfile.write (Zfobj.read (name))
Outfile.close ()
Config.my_queue.put ("Progresscontent---" + "decompression Complete")
How python compresses the extracted files