Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient way to delete a file if it's below a certain size [closed]

Tags:

python

What's the most efficient way to delete a file if it's less than 100k?

file = '/path/to/file.mov'
like image 826
ensnare Avatar asked Nov 26 '25 11:11

ensnare


1 Answers

You can use os.path.getsize (returns file size in bytes) and os.remove like that:

import os

file = '/path/to/file.mov'
if os.path.getsize(file) < 100 * 1024:
  os.remove(file)
like image 52
KL-7 Avatar answered Nov 28 '25 04:11

KL-7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!