-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileLinesCount.hs
33 lines (26 loc) · 934 Bytes
/
FileLinesCount.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module FileLinesCount where
import System.Directory
import System.IO
import Control.Applicative
main :: IO ()
main = do
total <- countDir "./"
print $ total
return ()
data NameWithLength=NameWithLength String Int deriving Show
countDir :: FilePath -> IO [NameWithLength]
countDir fp = do
f <- getDirectoryContents "."
all<-sequence [countFile ff | ff <- f, elem ff ["..","."] == False]
return $ concat all
countFile :: FilePath -> IO [NameWithLength]
countFile a = do
flag <- doesDirectoryExist a
case flag of
True -> countDir a
False -> sequence [getLineByFile a]
getLineByFile :: FilePath -> IO NameWithLength
getLineByFile fp = do
contents <- readFile fp
let all = lines contents
return $ NameWithLength fp (length all)