Question

Python3 - Deleting Files but keeping one

PasCam Q Search one cyHXH program12.py XgDrW 8ciRD twLJ9 look DEUOu YhEOQ AITG3 gaYS3 CkngY dUTKz

How would I go about keeping the file program12.py and deleting the rest?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We can simply do this by using the terminal:-

The following is the syntax for the deletion

cd <the directory you want>
find . -type f ! -iname "*.pdf" -delete

For example there is a directory called waste in your home folder.

cd ~/waste

then we can delete the files by finding

find . -type f ! -iname "*.pdf" -delete

This will delete all files except xyz.pdf.

Explanation of the command:-

. means current directory. ! means to take all files except the one with .pdf at the end. -delete means to delete it .

NOTE:-this command will delete all files including the hidden files

Add a comment
Know the answer?
Add Answer to:
Python3 - Deleting Files but keeping one How would I go about keeping the file program12.py...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT