This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Python script for compressing files in batches

By: a guest on Jul 17th, 2011  |  syntax: Python  |  size: 0.90 KB  |  views: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import os
  2. path="/storeM/fat/screenshots/active/"
  3. archiveFilename = '/storeM/fat/screenshots/7z/test2.7z'
  4. #ensure path string ends in '/'
  5. if path[len(path)-1] != '/':
  6.         path = path + '/'
  7.  
  8. dirList=os.listdir(path)
  9.  
  10. maxStackSize = 20
  11. splitBatches = {}
  12. batchStack = 0
  13. currentStack = []
  14. currentStackNumber = 0
  15.  
  16. #let's make some batches of a given size (ignore anything greater for now)
  17. for file in dirList:
  18.         if batchStack < maxStackSize:
  19.                 batchStack = batchStack + 1
  20.                 currentStack.append(path + file)
  21.         else:
  22.                 batchStack = 0
  23.                 splitBatches[currentStackNumber]=currentStack
  24.                 currentStack = []
  25.                 currentStackNumber = currentStackNumber + 1
  26.                
  27.  
  28. for batch in splitBatches:
  29.         batchOfFilenames = str(splitBatches[batch]).replace(',','').replace("'",'').replace('"','').replace('[','').replace(']','')
  30.         os.system('7za a '+ archiveFilename +' '+ batchOfFilenames)
  31.         os.system('rm '+ batchOfFilenames)
clone this paste RAW Paste Data