-3

I'm not sure how to use the getsize method. What I'd want to do with it is to quit the program if the file size is greater that the specified size.

LaurentiuS
  • 304
  • 3
  • 10
  • 1
    please show what you have tried – Ctznkane525 Jan 12 '18 at 19:35
  • 2
    Possible duplicate of [How to check file size in python?](https://stackoverflow.com/questions/2104080/how-to-check-file-size-in-python) – Pac0 Jan 12 '18 at 19:36
  • 1
    What exactly is the problem? Do you know how to get a file's size? Do you know how to quit the script? Do you know about if-statements? – Aran-Fey Jan 12 '18 at 19:37

2 Answers2

1

You can check the file size by using the code from this answer.

import os, sys
if os.path.getsize("/path/isa_005.mp3") > 5000:
    sys.exit(0)
Ubdus Samad
  • 1,218
  • 1
  • 15
  • 27
xavdid
  • 5,092
  • 3
  • 20
  • 32
0

Here is one method and some documentation on stat

import os
if os.stat('file.txt').st_size > 5000:
  quit()

https://docs.python.org/2/library/stat.html

EoinS
  • 5,405
  • 1
  • 19
  • 32