Advertisement
Peaser

filecut for windows

Jul 4th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import compressor,sys,os
  2. usg ="""usage:
  3. python filecut.py <path> <blocksize>
  4.  
  5. example: python filecut.py example.jpg 6
  6. """
  7.  
  8. try:
  9.     opened = sys.argv[1]
  10. except:
  11.     print usg
  12.     os.system("pause")
  13.     sys.exit(0)
  14. try:
  15.     lev = sys.argv[2]
  16.     lev = int(lev)
  17.     display = False
  18. except ValueError:
  19.     sys.exit(0)
  20. except:
  21.     display = True
  22.  
  23. levels = {
  24. 1:1024,
  25. 2:2048,
  26. 3:4096,
  27. 4:8192,
  28. 5:16384,
  29. 6:32768,
  30. 7:65536,
  31. 8:131072,
  32. 9:262144,
  33. 10:524288
  34. }
  35.  
  36. if display: #if accessed through command line or by dragging.
  37.  
  38.     for i in levels:
  39.         print str(i),":",str(levels[i])
  40.  
  41.     choose = raw_input("\nChoose block size (1 through 10)\n")
  42.  
  43.     def begin(obj):
  44.  
  45.         try:
  46.             obj = int(obj) #if not a number, error
  47.             if obj not in range(1,11):
  48.                 raise ValueError, "Not a valid choice" #if not 1 through 10, error
  49.             return obj
  50.         except ValueError:
  51.             print "\nInvalid input!\n"
  52.             os.system("pause")
  53.             sys.exit(0)
  54.     amount = levels[begin(choose)]
  55. else:
  56.     amount = levels[lev]
  57.  
  58. data = open(opened, "rb").read().encode("base64")
  59. blocksize = amount
  60. cuts = [data[i:i+blocksize] for i in range(0, len(data), blocksize)]
  61.  
  62. for i in cuts:
  63.     filename = str(hex(cuts.index(i)))+".txt"
  64.     with open(filename,'wb') as out:
  65.         out.write(i)
  66.         out.close()
  67.  
  68.     compressor.compress(filename,filename) #compress the file (Reduces size about 30% usually)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement