Using plow.py to delete files as replotting progresses

Hi, I’ve been using plow.py (gibhub below) to move my new plots to final HDD destinations. Currently, when a directory is full, plow.py will stop sending plots to that directory. Instead of stopping, I would like ploy.py to delete the largest file in that directory to make room. Would someone familiar with python/linux be able to help me?

The section I want to modify is here where it checks my new plot size to free space: line 114

           plot_size = plot.stat().st_size
            dest_free = shutil.disk_usage(dest).free
            if dest_free < plot_size:
                print(f"Farm {dest} is full")
                await plot_queue.put(plot)
                # Just quit the worker entirely for this destination.
                break

Instead of breaking, I’d like to change the behavior to delete he largest file in the directory to make room. Maybe the largest file ending in .plot just in case< :slight_smile:

Thank you!

This is made by someone else, not mine.
But I think this does what you are lookiing for

Thank you! Wow! That is much more complex than the original plow.py!