Deleting Matched Files
Let’s make the walk tool a little more useful by adding the ability to delete the files it finds. To do this, you’ll add another action to the tool and a new flag del of type bool, allowing the user to enable file deletion.
Learning how to write code that deletes files is an important aspect of creating tools that work with files and perform system administration tasks, but it comes with the risk that you might accidentally delete files you didn’t intend to delete. Make sure that your code is correct to prevent the accidental deletion of files on your computer. Never run this code as a privileged user, as it could cause loss of data or damage to your operating system’s files.
Let’s add another action function called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access