Course of Raku / Objects, I/O, and exceptions / Input and output / Deleting files and directories / Exercises / Delete a file

Solution: Delete a file

Here is a possible solution to the task.

Code

spurt 'note.txt', 'temporary';
say 'note.txt'.IO.e;

unlink 'note.txt';
say 'note.txt'.IO.e;

🦋 You can find the source code in the file delete-a-file.raku.

Output

True
False

Comments

  1. spurt creates the file, so the first .e test reports True.

  2. unlink deletes it. The second .e test then reports False, because the file is gone. Note the use of .e rather than .f: the type test .f would throw on a path that no longer exists, while .e simply answers False.

Course navigation

Delete a file   |   Clear a directory