0

I need to unzip numerous zipx files into directory while checking on the run if unzipped files comply with a condition. The condition is "if there is file with the same name overright it only if unzipped file is larger".

I wanted to control winzip with win32com but I couldn't find Object.Name with COM browser (win32com\client\combrowse.py). Also would be nice to find methods I could use with this winzip object.

Could anyone help with the way I choose or advice an easier option to solve the described problem. Thansk.

user1995926
  • 39
  • 1
  • 4

1 Answers1

1

Forget win32com. Instead,

  1. create a destination folder
  2. loop over zipx archives; for each one:
    1. create a temp folder using Python's tempfile module
    2. use the subprocess module to run your unzip utility (that handles zipx format) on the zipx archive, with command line option to extract to the temp folder created
    3. use the shutil module to copy each unzipped file in that folder to the common destination folder created in first step, if file meets the condition. For file size, use Path.stat().st_size or os.path.get_size().
    4. erase temp folder

So each archive gets unzipped to a different temp folder, but all extracted files get moved to one common folder. Alternately, you could use the same temp folder for all archives, but empty the folder at end of each iteration, and delete the temp folder at end of script.

  1. create a destination folder
  2. create a temp archive extraction folder using Python's tempfile module
  3. loop over zipx archives; for each one:
    1. use the subprocess module to run your unzip utility (that handles zipx format) on the zipx archive, with command line option to extract to the temp folder created
    2. use the shutil module to copy each unzipped file in that folder to the common destination folder created in first step, if file meets the condition. For file size, use Path.stat().st_size or os.path.get_size().
    3. erase contents of temp folder
  4. erase temp folder
Oliver
  • 27,510
  • 9
  • 72
  • 103
  • The main problem with zipx. There is no free unzip utility for this. That is why I'm trying to run specifically winzip with win32com – user1995926 Dec 25 '15 at 18:15
  • The solution I describe allows you to do this. I have edited, maybe clearer now. – Oliver Dec 25 '15 at 20:41