Course of Raku / Objects, I/O, and exceptions / Input and output / Deleting files and directories
Quiz — Deleting files
What does the following program print?
mkdir 'data';
spurt 'data/x.txt', 'hi';
rmdir 'data';
say 'data'.IO.e;| 1 | True |
| 0 | False |
| 0 | an error |
| 0 | Nil |
rmdir only removes an empty directory.
Here, data still contains x.txt, so
rmdir removes nothing and leaves the directory in place.
.e therefore still reports True. To delete the
directory you would first remove its contents (for example with
.unlink for 'data'.IO.dir) and then call
rmdir.