Skip to content

Instantly share code, notes, and snippets.

@chrisnorris
Last active September 11, 2019 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisnorris/6910e492ee73fb625934a7ba85d8bf40 to your computer and use it in GitHub Desktop.
Save chrisnorris/6910e492ee73fb625934a7ba85d8bf40 to your computer and use it in GitHub Desktop.
haskell script to recursively save directory names to file
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString as B hiding (filter)
import Data.Set (fromList, member)
import Data.Text as T hiding (filter)
import Data.Text.Encoding
import System.Directory
import System.FilePath.Windows
-- work around encoding problems
main = recursiveDirectoryNames "."
recursiveDirectoryNames source = listDirectory source >>= action
where
action [] = return ()
action target =
mapM_
( B.appendFile "results.txt". encodeUtf8. T.pack. (++ linebreak))
(directories target)
>> mapM_
(recursiveDirectoryNames . (source </>)) (directories target)
linebreak = "\r\n"
directories = filter $ \entry -> not (hasExtension || (entry `member` exceptions))
exceptions = fromList ["LICENSE"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment