Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to delete all pictures within my picture folder on my computer that conta

ID: 3722103 • Letter: I

Question

I want to delete all pictures within my picture folder on my computer that contain a cetain list of numbers (all photos are a number follwed by the extention .jpg. ex: 16.jpg, 27.jpg, 53.jpg) The list of numbers I want to delete are in a .txt file called "non.txt" with the path C:Users l80962Pictures. The pictures are in the same folder as the .txt file, and they are all .jpg pictures. For example, I want to keep 68.jpg, but I want to keep 89.jpg. How do I delete the pictures with the number givin in the txt file? I need this done in command line. Thanks!

Explanation / Answer

#!/bin/bash

file="/home/picture/data.txt" --------------Get the file path location.In this file contain list of picture need to be deleted.

while IFS= read -r line ------------------ Reads each line(Image name) by line and get a each image name until end of the file.

do

pictureFileLocation = "/home/picture/data" ---- picture file location

pictureFileLocation += $line ------------------by concate the pictureFileLocation and image name to be deleted

printf 'Deleting the file %s ' "$pictureFileLocation"-------print the deleted file location

if [ -f $pictureFileLocation ] ; then----check teh file exist or not,

rm $pictureFileLocation----------if tehre it will be removed.

fi

done <"$file"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote