aboutsummaryrefslogtreecommitdiff
path: root/lib/App/MediaControl/FS.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/MediaControl/FS.rakumod')
-rw-r--r--lib/App/MediaControl/FS.rakumod36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/App/MediaControl/FS.rakumod b/lib/App/MediaControl/FS.rakumod
new file mode 100644
index 0000000..b8f68d2
--- /dev/null
+++ b/lib/App/MediaControl/FS.rakumod
@@ -0,0 +1,36 @@
+use v6.d;
+
+class App::MediaControl::FS {
+ has IO::Path() $.root is required;
+ has $!extensions;
+
+ submethod TWEAK(:$extensions) {
+ $!extensions = any($extensions.Slip);
+ }
+
+ method get-children-of(Str $path) {
+ my $base = $!root.child($path);
+ return @() unless $base.d;
+
+ my @children = eager $base.dir(
+ test => -> $f {
+ my $based-f = $base.child($f);
+
+
+ $based-f.d ?? $f ~~ $*SPEC.curupdir !!
+ ($based-f.extension ~~ $!extensions) ?? True !!
+ False;
+ },
+ );
+
+ return @children.map(
+ -> $f {
+ %( name => $f.basename, is_dir => $f.d );
+ }
+ ).sort({ .<name> });
+ }
+
+ method exists(Str $path) {
+ return $!root.child($path).e;
+ }
+}