Course of Raku / Objects, I/O, and exceptions / Input and output / Working with directories / Exercises / File or directory?
Solution: File or directory?
Here is a possible solution to the task.
Code
spurt 'a.txt', 'x';
say 'a.txt'.IO.f;
say 'a.txt'.IO.d;🦋 You can find the source code in the file file-or-directory.raku.
Output
True
FalseComments
.ftests for a regular file, so it returnsTruefora.txt..dtests for a directory. Asked about the very same path, it returnsFalse, becausea.txtis a file, not a directory. The two tests are complementary, which is how you tell a file and a directory apart.