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)