Walk a directory/Non-recursively: Difference between revisions

Content added Content deleted
m (Added the Sidef language)
Line 797: Line 797:
end for;
end for;
end func;</lang>
end func;</lang>

=={{header|Sidef}}==
<lang ruby>'*.p[lm]'.glob.each { |file| say file }; # Perl files under this directory</lang>
{{out}}
<pre>
x.pl
x.pm
</pre>

<lang ruby>func file_match(callback is Block, pattern=/\.txt\z/, path=Dir.cwd) {
path.open(\var dir_h) || return;
dir_h.entries.each { |entry|
if (entry.basename ~~ pattern) {
callback(entry);
}
}
}

file_match(
path: %d'/tmp',
pattern: /\.p[lm]\z/i,
callback: { |file|
say file;
}
);</lang>
{{out}}
<pre>
/tmp/x.pl
/tmp/x.pm
</pre>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==