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

Haskell: Exploring System.Directory package

In this post and subsequent posts, I am going to explain about System.Directory package.  System.Directory provides number of system independent functions for directory manipulation. Following table summarizes all the functions in System.Directory package.

Function
Signature
Description
createDirectory
createDirectory :: Filepath -> IO ()
Create a directory
createDirectoryIfMissing
createDirectoryIfMissing :: Bool -> FilePath -> IO ()
Create directory if not exist
removeDirectory
removeDirectory :: FilePath -> IO ()
Remove an existing directory
removeDirectoryRecursive
removeDirectoryRecursive :: FilePath -> IO ()
Remove directories and sub directories
renameDirectory
renameDirectory :: FilePath -> FilePath -> IO ()
Rename a directory
getDirectoryContents
getDirectoryContents :: FilePath -> IO [FilePath]
List all entries in the directory including special entries ., ..
getCurrentDirectory
getCurrentDirectory :: IO FilePath
Get current working directory.
setCurrentDirectory:

setCurrentDirectory :: FilePath -> IO ()
Change working directory
getHomeDirectory
getHomeDirectory :: IO FilePath
Get user home directory
listDirectory
listDirectory :: FilePath -> IO [FilePath]
List all entries in the directory.
withCurrentDirectory
withCurrentDirectory :: FilePath -> IO a -> IO a
Run IO action with given directory
getTemporaryDirectory
getTemporaryDirectory :: IO FilePath
Get the directory for temporary files
removeFile
removeFile :: FilePath -> IO ()
Remove file
renameFile
renameFile :: FilePath -> FilePath -> IO ()
Rename file
copyFile
copyFile :: FilePath -> FilePath -> IO ()
Copy file
canonicalizePath
canonicalizePath :: FilePath -> IO FilePath
Replace ., .. with actual path
makeAbsolute
makeAbsolute :: FilePath -> IO FilePath
Convert path to absolute path
makeRelativeToCurrentDirectory
makeRelativeToCurrentDirectory :: FilePath -> IO FilePath
Construct a path relative to current directory
findExecutable
findExecutable :: String -> IO (Maybe FilePath)
Get the path of given executable
findExecutables
findExecutables :: String -> IO [FilePath]
Get all the paths of executable file
findExecutablesInDirectories
findExecutablesInDirectories:: [FilePath] -> String -> IO [FilePath]
Search for an executable in given directories
findFile
findFile :: [FilePath] -> String -> IO (Maybe FilePath)
Search for a file in given directories
findFiles
findFiles :: [FilePath] -> String -> IO [FilePath]
Search for a file in given directories
findFilesWith
findFilesWith:: (FilePath -> IO Bool) -> [FilePath] -> String -> IO [FilePath]
Get all the files that satisfiy given property
emptyPermissions
emptyPermissions :: Permissions
Return Permissions instance by clearing all.

Prelude System.Directory> emptyPermissions
Permissions {readable = False, writable = False, executable = False, searchable = False}
readable
readable :: Permissions -> Bool
Return True, if the Permissions instance has the property readable = True, else False.
writable
writable :: Permissions -> Bool
Return True, if the Permissions instance has the property writable = True, else False.
executable
executable :: Permissions -> Bool
Return True, if the Permissions instance has the property executable = True, else False.
searchable
searchable :: Permissions -> Bool
Return True, if the Permissions instance has the property searchable = True, else False
setOwnerReadable
setOwnerReadable :: Bool -> Permissions -> Permissions
If the Bool argument is True, it sets the readable permission to the owner, else unset.
setOwnerWritable
setOwnerWritable :: Bool -> Permissions -> Permissions
If the Bool argument is True, it sets the writable permission to the owner, else unset.
setOwnerExecutable
setOwnerExecutable :: Bool -> Permissions -> Permissions
If the Bool argument is True, it sets the executable permission to the owner, else unset.
setOwnerSearchable
setOwnerSearchable :: Bool -> Permissions -> Permissions
If the Bool argument is True, it sets the searchable permission to the owner, else unset.
getPermissions
getPermissions :: FilePath -> IO Permissions
Get the permissions of a file (or) directory.
setPermissions
setPermissions :: FilePath -> Permissions -> IO ()
Set permissins to given file.
copyPermissions
copyPermissions :: FilePath -> FilePath -> IO ()
Copy permissions of one file to other.
getAccessTime
FilePath -> IO UTCTime
Get the time at which the file or directory was last accessed.
getModificationTime
FilePath -> IO UTCTime
Get the time at which the file or directory was last modified.
setAccessTime
FilePath -> UTCTime -> IO () Source
Change the time at which the file or directory was last accessed.
setModificationTime
FilePath -> UTCTime -> IO ()
Change the time at which the file or directory was last modified.

Following functions are used to check file/directory existence.
doesFileExist: Check for file existance
doesDirectoryExist: Check for directory existence

Following function is used to get the extension of executable file.


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

Share the post

Haskell: Exploring System.Directory package

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×