TahelNadav
TahelNadav

Reputation: 21

How to read all file names from directory?

How do I read all file names from a directory in Haskell?

I tried to use the getDirectoryContents function and put:

import System.Directory (doesDirectoryExist, getDirectoryContents)

but it gave an error on the import:

Could not load module ‘System.Directory’
It is a member of the hidden package ‘directory-1.3.6.0’.
You can run ‘:set -package directory’ to expose it.

Where should I run :set -package directory?

Upvotes: 2

Views: 152

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 152682

That error looks like a ghci error. If so, then you can simply enter the :set command directly into ghci.

For ghc itself, you may look into ghc-pkg for the very low-level control or cabal for a more sensible user experience. With the latter, you would list directory in the build-depends field of the appropriate library or executable stanze in your whatever.cabal file, then use cabal repl to interact with ghci instead of using ghci directly. (There are more gentle, detailed introductions to this tool elsewhere -- just have a Google.)

Upvotes: 2

Related Questions