How to resolve the algorithm Walk a directory/Non-recursively step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Walk a directory/Non-recursively step by step in the Clojure programming language
Table of Contents
Problem Statement
Walk a given directory and print the names of files matching a given pattern.
(How is "pattern" defined? substring match? DOS pattern? BASH pattern? ZSH pattern? Perl regular expression?)
Note: This task is for non-recursive methods. These tasks should read a single directory, not an entire directory tree.
Note: Please be careful when running any code presented here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Walk a directory/Non-recursively step by step in the Clojure programming language
Source code in the clojure programming language
(import java.nio.file.FileSystems)
(defn match-files [f pattern]
(.matches (.getPathMatcher (FileSystems/getDefault) (str "glob:*" pattern)) (.toPath f)))
(defn walk-directory [dir pattern]
(let [directory (clojure.java.io/file dir)]
(map #(.getPath %) (filter #(match-files % pattern) (.listFiles directory)))))
You may also check:How to resolve the algorithm Ludic numbers step by step in the Arturo programming language
You may also check:How to resolve the algorithm Tonelli-Shanks algorithm step by step in the Raku programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the EMal programming language
You may also check:How to resolve the algorithm Perfect shuffle step by step in the Julia programming language
You may also check:How to resolve the algorithm Klarner-Rado sequence step by step in the AppleScript programming language