Python Forum
Looping through files, check content and delete
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping through files, check content and delete
#1
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?
Reply
#2
yes. you will need the json module from standard library to read the json files.
there are multiple different ways to iterate over files.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] list content check paul18fr 6 683 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  delete all files and subdirectory from a main folder mg24 7 1,586 Oct-28-2022, 07:55 AM
Last Post: ibreeden
  delete all files which contains word sql_Table1 mg24 2 853 Sep-15-2022, 10:05 PM
Last Post: mg24
  Delete empty text files [SOLVED] AlphaInc 5 1,546 Jul-09-2022, 02:15 PM
Last Post: DeaD_EyE
  Delete files from amazon s3 bucket python_student 0 3,918 Jan-14-2022, 04:51 PM
Last Post: python_student
  Looping through Folder structure and get files mfkzolo 0 1,889 Nov-02-2020, 08:31 AM
Last Post: mfkzolo
  How do I read the HTML files in a directory and write the content into a CSV file? glittergirl 1 2,586 Sep-23-2019, 11:01 AM
Last Post: Larz60+
  Looping through music files (SOLVED) ebolisa 0 2,496 Jul-13-2019, 06:16 PM
Last Post: ebolisa
  Delete Lines that Contain Words - Loop through files in a folder - Write to new files dj99 3 3,438 May-18-2019, 06:34 AM
Last Post: heiner55
  How to concatenate files while looping through lists? python_newbie09 3 2,867 Mar-24-2019, 03:11 PM
Last Post: python_newbie09

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020