Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: removeDirectory: Remove an existing directory

System.Directory module provides removeDirectory function, which takes a Directory Full Path as an argument and removes it. Following is the signature of the removeDirectory function.

Prelude System.Directory> :t removeDirectory
removeDirectory :: FilePath -> IO ()

As per the documentation, you may get following erros while working with removeDirectory function.

Error
Description
HardwareFault
A physical I/O error has occurred.
InvalidArgument
FilePath is not a valid directory name.
isDoesNotExistError/ NoSuchThing
The directory does not exist.
isPermissionError / PermissionDenied
The process has insufficient privileges to perform the operation.
UnsatisfiedConstraints
Implementation-dependent constraints are not satisfied like .
UnsupportedOperation
The implementation does not support removal in this situation.
InappropriateType
The operand refers to an existing non-directory object.


DirectoryUtil.hs
{- Take directory name as input and create a directory -}
import System.IO
import System.Directory

main = do
putStrLn "Enter Directory Full path to remove"
direcotryName getLine

removeDirectory direcotryName
putStrLn "Directory removed"

$ runghc DirectoryUtil.hs 
Enter directory full path to remove
/Users/harikrishna_gurram/today/evenings/1
Directory removed


removeDirectory fail with an error, if the directory is not empty.
$ runghc DirectoryUtil.hs 
Enter directory full path to remove
/Users/harikrishna_gurram/today
DirectoryUtil.hs: /Users/harikrishna_gurram/today: removeDirectory: unsatisfied constraints (Directory not empty)



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: removeDirectory: Remove an existing directory

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×