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 |
||
dirWalk :: (FilePath -> IO ()) -> FilePath -> IO () |
|||
dirWalk filefunc top = do |
|||
isDirectory <- doesDirectoryExist top |
isDirectory <- doesDirectoryExist top |
||
if isDirectory |
if isDirectory |
||
then |
then do |
||
files <- listDirectory top |
|||
do |
|||
mapM_ (dirWalk filefunc . (top </>)) files |
|||
⚫ | |||
mapM_ (\file -> dir_walk (top </> file) filefunc) files |
|||
else |
|||
⚫ | |||
main :: IO () |
main :: IO () |
||
main = do |
main = do |
||
hSetEncoding stdout utf8 |
|||
hSetEncoding stdin utf8 |
|||
let worker fname |
|||
| takeExtension fname == ".hs" = putStrLn fname |
|||
| otherwise = return () |
|||
dirWalk worker "."</lang> |
|||
else return () |
|||
dir_walk "." worker</lang> |
|||
== Icon and Unicon == |
== Icon and Unicon == |