Advertisement
metalx1000

Python progress of single file copy progressbar

Jul 21st, 2016
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import os
  3.  
  4. SOURCE_FILENAME="/tmp/2.png"
  5. TARGET_FILENAME="/tmp/3.png"
  6.  
  7. source_size = os.stat(SOURCE_FILENAME).st_size
  8. copied = 0
  9. source = open(SOURCE_FILENAME, 'rb')
  10. target = open(TARGET_FILENAME, 'wb')
  11.  
  12. while True:
  13.     chunk = source.read(32768)
  14.     if not chunk:
  15.         break
  16.     target.write(chunk)
  17.     copied += len(chunk)
  18.     print '\r%02d%%' % (copied * 100 / source_size),
  19.  
  20. source.close()
  21. target.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement