What I want is to write a Haskell function to return the files of current directory e.g
Change the current directory to
:cd c:/code/haskell
Then write a function which returns the files in a set e.g
[x | x <-getDirectoryContents ]
Edited:
I have wrote a function sth like this which lists files (ref: http://zvon.org/other/haskell/Outputdirectory/index.html)
import Directory
main = _dir "/tmp/FOO"
_dir _path =do
setCurrentDirectory _path
_cd <- getCurrentDirectory
print _cd
_file <- getDirectoryContents _cd
print _file
so calling _dir "c:/code/haskell" will list all files + directory names (non-recursive) . What I want now is to call this in a predicate function, for example:
[ x| x <- _dir "c:/code/haskell" | x start with 'haskell_' ]
so I can apply a filter on file name
You can use the DIR command by itself (just type “dir” at the Command Prompt) to list the files and folders in the current directory.
The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.
Type dir /A:D. /B > FolderList. txt and press Enter to generate a top-level folder list. When the list is complete, a new, blank prompt with a flashing cursor will appear.
It seems you are looking for:
getDirectoryContents :: FilePath -> IO [FilePath]
Refer : http://www.haskell.org/ghc/docs/6.12.2/html/libraries/directory-1.0.1.1/System-Directory.html#1
How about the following:
import Data.List
import System.Directory
main = do all <- getDirectoryContents "/tmp/FOO"
let filtered = filter (isPrefixOf "haskell") all
print filtered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With