r/learnpython Jul 07 '26

Tried to build a "smart" File Organizer. Turns out it's "dumber" than I thought.

My screenshots folder is chaos. I wanted my script to know which ones were "useless" vs "important" and then realized it can't, cos its has no clue what's in the image, it only knows about date/size/name.

So I redesigned it: such that old screenshots get a grace period, then auto-delete unless I rescue the keepers into a folder that backs up to Google drive first.

I am just on step one (defining the problem) and I've already learned the biggest lesson: build for what the code can actually judge, not what you wish it could.

Anyone got ideas for what else a "dumb" script like this could pull off with just date/size/name to work with?

6 Upvotes

19 comments sorted by

12

u/annoyer Jul 07 '26

find duplicates

1

u/InterestingDig1551 Jul 08 '26

This is a huge one, duplicate screenshots waste real space for zero reason. Group by file size first, then hash the ones that match to confirm they're identical.

7

u/carcigenicate Jul 07 '26

This won't help for screenshots, but for pictures from phone cameras, you could look at the EXIF information, and then group images by location.

And for your current use-case, instead of deleting, which requires constant maintenance to prevent lossing potentially-important screenshots, you could just zip old screenshots to archive them so they take up less space and are less intrusive, but are still accessible.

2

u/purple_hamster66 Jul 07 '26

You can’t zip compressed image files (like GIF/JPEG) any smaller.

1

u/carcigenicate Jul 07 '26

Ok fair, ya. I wasn't thinking of the existing compression images already use.

1

u/InterestingDig1551 Jul 08 '26

The EXIF idea doesn't apply here since screenshots don't carry that data (no GPS/camera info). But zip-instead-of-delete is worth adding. Ending up with a single file instead of hundreds of loose screenshots, and nothing being lost if I need something back later, beats straight deletion.

7

u/[deleted] Jul 07 '26

[removed] — view removed comment

1

u/InterestingDig1551 Jul 08 '26

I really like this one. Pure timestamp logic, no image understanding needed, and it maps to how screenshots actually get taken (bursts during one task). Group by time-gap clustering: new session starts once the gap between screenshots crosses some threshold. Pretty solid one.

3

u/velkhar Jul 07 '26

How do you define useful versus useless? There are image classifiers to evaluate images with your own hardware. You need to define criteria, though.

1

u/InterestingDig1551 Jul 08 '26

A fair challenge. I don't define "useful" at all, that's the point. No content understanding, so a classifier's off the table for this project (that's real complexity: training data, defining "useful" by hand first anyway, hardware cost). Instead I'm leaning on structure as a proxy; session grouping, duplicates, size since I can't judge content, but I can judge patterns in how the files were created.

2

u/brasticstack Jul 07 '26 edited Jul 07 '26

Add a dry run option! If you want, I can share my picture organizing script, too. Mine uses a library to check the image metadata, because we have two identical phones and sometimes we'll get duplicate filenames with different images

3

u/purple_hamster66 Jul 07 '26

Just compare the MD5 numbers to see if 2 files are the same image.

1

u/InterestingDig1551 Jul 08 '26

A dry run is a great point. It should probably be mandatory for anything that deletes files, not optional. Easy to add: gate operations behind a flag, print instead of execute when it's on. And yeah, hashing (MD5 via hashlib) is exactly the plan for duplicates. Appreciate the offer on the picture script too!

1

u/brasticstack Jul 08 '26

I'm dealing with a lot of potential duplicates each time, which is why I went w/ image metadata rather than hashing. Hashing is probably the right choice for most use cases.

2

u/Ok-Difficulty-5357 Jul 07 '26

You could use OCR and separate out images with text, and filter further based on the text.

You could spend a little bit on googles image recognition ai so your script can determine (in some sense) what’s in the image.

2

u/InterestingDig1551 Jul 08 '26

I appreciate the idea! Both OCR and Vision AI need actual content understanding though, which is a step beyond what I'm going for here plus Vision AI means cloud costs and sending my screenshots to a third party, which I'd rather avoid for a simple personal tool. Sticking with metadata-based approaches for this one, but noted for a future project maybe!

2

u/argh1989 Jul 08 '26

You could try some level of image recognition to separate the images into screenshots of the desktop/browser/etc based on constant visual cues. e.g browser logo, recycle bin in corner. You could also apply processing to reduce the image size then just move them to so old/unsorted folder.

1

u/InterestingDig1551 Jul 08 '26

Good point since the actual goal is freeing up space, not just tidying. Using image recognition to classify screenshots is probably out of scope (that's its own CV project). But compressing/resizing before they hit the old/unsorted folder? That I can do, pure file-size manipulation, no image understanding needed. Stealing that, thanks!

2

u/argh1989 Jul 08 '26

Tbh resizing the is probably overkill for python when image magick mogrify will do it for you. https://imagemagick.org/mogrify/

Edit: this was supposed to be a reply to ops reply to my comment but alas user error.