0

Hello I am attempting to unzip a folder using a python sub-process similar to the instructions detailed here: 4th Solution Down in this thread

I have the following code:

Z_Location = 'C:\\Program Files (x86)\\7-Zip\\7zFM.exe'
Extract_File ='C:\\Users\\jnardone\\Desktop\\containszips\\myzipfile.zip'
Extract_PW = 'PASSWORD'
Extact_Folder = 'C:\\Users\\jnardone\\Desktop\\containsunzips'

Extract_Target = Z_Location + ' e ' + '"' + Extract_File + '"' + ' -p' + '"' + Extract_PW + '"' + ' -o' + '"' + Extact_Folder + '"'

subprocess.call(Extract_Target)

When I run this process however it just opens a 7zip window that is targeting my Pycharm file or my jupyter notebook file. See attached image:

enter image description here

I believe the targeting of my subprocess is off somewhere, I have tried using an os path as well, but I am unsure of syntax.

UPDATE:

I have changed the subprocess to work in my computer's directory instead of the notebook/IDE. However now I am seeing another issue of the zipped file not being unzipped, but duplicated.

subprocess.call(r"C:\Program Files (x86)\7-Zip\7z.exe e C:\Users\jnardone\Desktop\folder\file.7z -pPASSWORD",cwd=r'C:\Users\jnardone\Desktop\auto_test_3')

enter image description here

Joseph P Nardone
  • 150
  • 2
  • 12
  • 1
    Are you sure that your 7zip isn't just opening up to the default location? – FanMan Sep 17 '18 at 15:40
  • I have made an edit to force my sub process to function in the directory of my PC instead of the jupyter notebook/pycharm environment. I will update my question with the new code. – Joseph P Nardone Sep 17 '18 at 19:03

1 Answers1

0

The solution included the following:

  1. Changing the current working directory out of the Pycharm/Jupyter directory.
  2. Changing the archive target to the main folder containing the zip file, not targeting directly to the zipped file.

Hopefully this saves others some time as I was unable to find my issue though it was simple.

Joseph P Nardone
  • 150
  • 2
  • 12