Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cleanup without .hs files
import System.Directory
import Data.List
findDotIndex :: String -> Int
findDotIndex a = case findIndex (=='.') a of
Just x -> x
otherwise -> 0
splitAtDot :: String -> (String, String)
splitAtDot x = splitAt (findDotIndex x) x
forRemove :: (String, String) -> Bool
forRemove (_, ".") = False
forRemove (_, "..") = False
forRemove (_, ".hs") = False
forRemove (_, ".git") = False
forRemove (_, "cleanup") = False
forRemove _ = True
main = do
d <- getCurrentDirectory
c <- getDirectoryContents d
let splitted = map splitAtDot c
let target = filter forRemove splitted
let targetFiles = map (\(a, b) -> a ++ b) target
mapM (\file -> removeFile file) targetFiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.