'Renaming the folder zip file extracts to

Might just be an edge case but I extracted a zip file to a directory using the zip file module. When extracting, zip file names the directory it extracts to.

If there is a way I get to specify the name of the folder Zip file creates to extract the files to? I am hitting an error because I am using the same folder zipped up to test zip file and it keeps using the old folder name which already exists so it throws an error. Here is my code:

orginalFolderName = jobFolder + name
      with zipfile.ZipFile(directory,"r") as zip_ref:
        zip_ref.extractall(jobFolder)
      os.rename(orginalFolderName, newFoldername)
      directory = newFoldername


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source