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
34
35
36
37
38
39
40
| --Tree.hs
module Main (main) where
import Control.Monad
import Data.List
import System.Directory
import System.Environment
main = do
args <- getArgs
let path = args !! 0
allEntries <- getDirectoryContents path
let rippedEntries = allEntries \\ [".", ".."]
let entries = [path ++ "/"++ ent | ent <- rippedEntries]
mapM_ (flip viewEntry 1) entries
getDepthString:: Int -> String
getDepthString depth = show $ concat $ replicate depth " "
viewEntry entry depth= do
isDir <- doesDirectoryExist entry
if isDir
then viewDir entry $ depth +1
else viewFile entry $ depth +1
viewDir dir depth=
do putStrLn $ (getDepthString depth) ++ "|" ++ dir ++ " DIR"
allEntries <- getDirectoryContents dir
let rippedEntries = allEntries \\ [".", ".."]
let entries = [dir ++ "/"++ ent | ent <- rippedEntries]
mapM_ (flip viewEntry 1) entries
viewFile file depth=
do putStrLn $ (getDepthString depth) ++ "--" ++ file ++ " FILE"
|