Search code examples
pythonsubprocessunzip7zip

Python Subprocess Opening My Pycharm Folder and Jupyter Folder Instead of Target


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


Solution

  • 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.