Skip to content

Instantly share code, notes, and snippets.

@Jxck
Created June 11, 2012 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Jxck/2910543 to your computer and use it in GitHub Desktop.
Save Jxck/2910543 to your computer and use it in GitHub Desktop.
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