Walk a directory/Recursively: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Add Python 3 method via pathlib.Path.rglob())
m (→‎{{header|Haskell}}: Minor tidying, applied hlint, hindent.)
Line 1,017: Line 1,017:
import System.IO
import System.IO


dir_walk :: FilePath -> (FilePath -> IO ()) -> IO ()
dirWalk :: (FilePath -> IO ()) -> FilePath -> IO ()
dir_walk top filefunc = do
dirWalk filefunc top = do
isDirectory <- doesDirectoryExist top
isDirectory <- doesDirectoryExist top
if isDirectory
if isDirectory
then
then do
files <- listDirectory top
do
files <- listDirectory top
mapM_ (dirWalk filefunc . (top </>)) files
else filefunc top
mapM_ (\file -> dir_walk (top </> file) filefunc) files
else
filefunc top


main :: IO ()
main :: IO ()
main = do
main = do
hSetEncoding stdout utf8
hSetEncoding stdout utf8
hSetEncoding stdin utf8
hSetEncoding stdin utf8
let worker fname =
let worker fname
do if (takeExtension fname == ".hs")
| takeExtension fname == ".hs" = putStrLn fname
then putStrLn fname
| otherwise = return ()
dirWalk worker "."</lang>
else return ()
dir_walk "." worker</lang>


== Icon and Unicon ==
== Icon and Unicon ==