Advertisement
Guest User

compression

a guest
Feb 13th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import os
  2. import subprocess as sp
  3.  
  4. allFiles = []
  5. currentFile = ""
  6. #workingDir = "G:\Games\Console\Sony - PSP"
  7. workingDir = "H:\Test"
  8. #fileType = ".iso"
  9. fileType = ".bin"
  10. archiverPath = 'C:\\x64\\7za.exe'
  11.  
  12. def getFiles(workingDir):
  13.     for root, dirs, files in os.walk(workingDir):
  14.         for file in files:
  15.             if file.endswith(fileType):
  16.                 allFiles.append(os.path.join(root, file))
  17.                 #print(os.path.join(root, file))
  18.  
  19. def compress(allFiles):
  20.     for i in allFiles:
  21.         #os.system('C:\\x64\\7za.exe a -mx9 -ms=off ' + '"' + i.replace('.iso', '.7z') + '"' + ' ' + '"' + i + '"')
  22.         compress = sp.run([archiverPath, 'a', '-mx9', '-ms=off', i.replace(fileType, '.7z'), i], stdout = sp.PIPE, stderr = sp.STDOUT)
  23.         print('C:\\x64\\7za.exe a -mx9 -ms=off ' + '"' + i.replace('.iso', '.7z') + '"' + ' ' + '"' + i + '"')
  24.  
  25.         test = sp.run([archiverPath, 't', i.replace(fileType, '.7z')], stdout=sp.PIPE, stderr=sp.STDOUT)
  26.  
  27.         if test.returncode >= 2:
  28.             print ('Broken')
  29.         else:
  30.             os.remove(i)
  31.  
  32.  
  33. getFiles(workingDir)
  34. compress(allFiles)
  35.  
  36.  
  37.  
  38. print (allFiles)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement