Skip to content

Instantly share code, notes, and snippets.

@samebchase
Created February 12, 2024 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samebchase/9e4a17c1379ca2e2bb3d7bf72e1f2ff8 to your computer and use it in GitHub Desktop.
Save samebchase/9e4a17c1379ca2e2bb3d7bf72e1f2ff8 to your computer and use it in GitHub Desktop.
Creating an empty file nested in directories. aka mkdir -p followed by touch.
#!/usr/bin/env raku
use v6.d
sub MAIN($path-to-file) {
my $path = IO::Path.new: $path-to-file;
try {
mkdir $path.dirname;
CATCH {
when X::IO::Mkdir {
die "Failed to create the parent directory due to:\n{.message}";
}
}
}
try {
spurt($path);
CATCH {
default {
die "Failed to create file due to:\n{.message}";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment