write_file_size.py 443 B

123456789101112131415
  1. #!/usr/bin/env python
  2. import sys
  3. import os.path
  4. if __name__ == '__main__':
  5. output = sys.argv[1]
  6. size_sum = 0
  7. for filename in sys.argv[2:]:
  8. if os.path.exists(filename):
  9. size_sum += os.path.getsize(filename)
  10. else:
  11. sys.stderr.write('write_file_size.py: {0}: No such file or directory\n'.format(filename))
  12. sys.exit(1)
  13. with open(output, 'w') as f:
  14. f.write(str(size_sum))