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 :: FilePath -> IO
()
|
Create a directory
|
|
createDirectoryIfMissing :: Bool ->
FilePath -> IO ()
|
Create directory if not exist
|
|
removeDirectory :: FilePath -> IO
()
|
Remove an existing directory
|
|
removeDirectoryRecursive :: FilePath
-> IO ()
|
Remove directories and sub directories
|
|
renameDirectory :: FilePath ->
FilePath -> IO ()
|
Rename a directory
|
|
getDirectoryContents :: FilePath ->
IO [FilePath]
|
List all entries in the directory
including special entries ., ..
|
|
getCurrentDirectory :: IO FilePath
|
Get current working directory.
|
|
|
setCurrentDirectory :: FilePath ->
IO ()
|
Change working directory
|
getHomeDirectory :: IO FilePath
|
Get user home directory
|
|
listDirectory :: FilePath -> IO
[FilePath]
|
List all entries in the directory.
|
|
withCurrentDirectory :: FilePath ->
IO a -> IO a
|
Run IO action with given directory
|
|
getTemporaryDirectory :: IO FilePath
|
Get the directory for temporary files
|
|
removeFile :: FilePath -> IO ()
|
Remove file
|
|
renameFile :: FilePath -> FilePath
-> IO ()
|
Rename file
|
|
copyFile :: FilePath -> FilePath
-> IO ()
|
Copy file
|
|
canonicalizePath :: FilePath -> IO
FilePath
|
Replace ., .. with actual path
|
|
makeAbsolute :: FilePath -> IO
FilePath
|
Convert path to absolute path
|
|
makeRelativeToCurrentDirectory ::
FilePath -> IO FilePath
|
Construct a path relative to current
directory
|
|
findExecutable :: String -> IO
(Maybe FilePath)
|
Get the path of given executable
|
|
findExecutables :: String -> IO
[FilePath]
|
Get all the paths of executable file
|
|
findExecutablesInDirectories::
[FilePath] -> String -> IO [FilePath]
|
Search for an executable in given
directories
|
|
findFile :: [FilePath] -> String
-> IO (Maybe FilePath)
|
Search for a file in given directories
|
|
findFiles :: [FilePath] -> String
-> IO [FilePath]
|
Search for a file in given directories
|
|
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.
exeExtension: Get the extension of
executable file.
No comments:
Post a Comment