Last active
February 22, 2022 17:02
-
-
Save jship/917cd3cbcbbe1943c9fd885d48fd978b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified System.Directory as Directory | |
import qualified System.Environment as Environment | |
import qualified System.FilePath as FilePath | |
listDirectoryDeep :: FilePath -> IO [FilePath] | |
listDirectoryDeep directory = do | |
entries <- listDirectoryShallow directory | |
foldMap listEntry entries | |
where | |
listEntry entry = do | |
isDirectory <- Directory.doesDirectoryExist entry | |
isSymLink <- Directory.pathIsSymbolicLink entry | |
if not isDirectory || isSymLink then | |
pure [entry] | |
else | |
listDirectoryDeep entry | |
listDirectoryShallow :: FilePath -> IO [FilePath] | |
listDirectoryShallow directory = do | |
entries <- Directory.listDirectory directory | |
pure $ fmap (FilePath.combine directory) entries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment