Python Forum

Full Version: Looping through files, check content and delete
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear Python Experts,

I wonder if it is possible to write a small python program
that goes through my 50 000 .json files on my windows machine and deletes every .json file that conains "throttle":"0" or "throttile":"0.0"
as well as an image that is in the same folder and named in the .json file "cam/image_array": "xxxxxxxxx.jpg"

I imagine looping through all .json files and if the pattern is found, extracting first the image name and deleting the image
and second deleting the json file, then go to next file.

Is something like that possible?
yes. you will need the json module from standard library to read the json files.
there are multiple different ways to iterate over files.