Unzip Zip File to Directory and List Files

  • Share this:

Code introduction


This function is used to unzip all files from a zip file into a specified directory and return a list of all files in that directory.


Technology Stack : zipfile, os

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zip_file_files_to_dir(zip_path, output_dir):
    import zipfile
    import os

    with zipfile.ZipFile(zip_path, 'r') as zip_ref:
        zip_ref.extractall(output_dir)
        
    return os.listdir(output_dir)                
              
Tags: