1234567891011121314151617181920212223 |
- #!/usr/bin/ruby
- #
- ## https://rosettacode.org/wiki/Walk_a_directory/Non-recursively#Sidef
- #
- func file_match(Block callback, 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;
- }
- );
|