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;
1True
0False
0an error
0Nil

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.

Course navigation

Solution: Clear a directory   |   File handles