Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/conformance98/Directory/getDirContents/Main.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


import Directory
import List

main = do
  d <- getCurrentDirectory
  putStrLn ("Current Dir: "++lastdir 4 d)
  fs <- getDirectoryContents d
  mapM_ (\f-> putStrLn ("    "++f)) (sort fs)

splitWith :: (a -> Bool) -> [a] -> [[a]]
splitWith p s =
   let (l, s') = break p s
   in  l : case s' of
           [] -> []
           (_:rest) -> splitWith p rest

lastdir :: Int -> FilePath -> FilePath
lastdir n = concat . intersperse "/"
            . reverse . take n . reverse . splitWith (=='/')

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.