Copyright | (C) 2004 The University of Glasgow. (C) 2017 XT et al. |
---|---|
License | BSD-style (see the LICENSE file) |
Maintainer | e@xtendo.org |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This is the module for the RawFilePath
version of functions in the
directory
package.
- type RawFilePath = ByteString
- doesPathExist :: RawFilePath -> IO Bool
- doesFileExist :: RawFilePath -> IO Bool
- doesDirectoryExist :: RawFilePath -> IO Bool
- getHomeDirectory :: IO (Maybe RawFilePath)
- getTemporaryDirectory :: IO ByteString
- listDirectory :: RawFilePath -> IO [RawFilePath]
- getDirectoryFiles :: RawFilePath -> IO [RawFilePath]
- getDirectoryFilesRecursive :: RawFilePath -> IO [RawFilePath]
- createDirectory :: RawFilePath -> IO ()
- createDirectoryIfMissing :: Bool -> RawFilePath -> IO ()
- removeFile :: RawFilePath -> IO ()
- tryRemoveFile :: RawFilePath -> IO ()
- removeDirectory :: RawFilePath -> IO ()
- removeDirectoryRecursive :: RawFilePath -> IO ()
Documentation
type RawFilePath = ByteString #
A literal POSIX file path
Nondestructive (read-only)
doesPathExist :: RawFilePath -> IO Bool Source #
Test whether the given path points to an existing filesystem object. If the user lacks necessary permissions to search the parent directories, this function may return false even if the file does actually exist.
doesFileExist :: RawFilePath -> IO Bool Source #
doesDirectoryExist :: RawFilePath -> IO Bool Source #
getHomeDirectory :: IO (Maybe RawFilePath) Source #
Returns the current user's home directory. More specifically, the value
of the HOME
environment variable.
The directory returned is expected to be writable by the current user, but
note that it isn't generally considered good practice to store
application-specific data here; use getXdgDirectory
or
getAppUserDataDirectory
instead.
The operation may fail with:
UnsupportedOperation
The operating system has no notion of home directory.isDoesNotExistError
The home directory for the current user does not exist, or cannot be found.
getTemporaryDirectory :: IO ByteString Source #
Return the current directory for temporary files. It first returns the
value of the TMPDIR
environment variable or "/tmp" if the variable
isn't defined.
:: RawFilePath | The path of directory to inspect |
-> IO [RawFilePath] | A list of files in the directory |
Get a list of files in the specified directory, excluding "." and ".."
ghci> listDirectory "/" ["home","sys","var","opt","lib64","sbin","usr","srv","dev","lost+found","bin","tmp","run","root","boot","proc","etc","lib"]
:: RawFilePath | The path of directory to inspect |
-> IO [RawFilePath] | A list of files in the directory |
Get a list of files in the specified directory, including "." and ".."
ghci> getDirectoryFiles "/" ["home","sys","var","opt","..","lib64","sbin","usr","srv","dev","lost+found","mnt","bin","tmp","run","root","boot",".","proc","etc","lib"]
getDirectoryFilesRecursive Source #
:: RawFilePath | The path of directory to inspect |
-> IO [RawFilePath] | A list of relative paths |
Recursively get all files in all subdirectories of the specified directory.
*System.RawFilePath> getDirectoryFilesRecursive "src" ["src/System/RawFilePath.hs"]
Destructive
createDirectory :: RawFilePath -> IO () Source #
Create a new directory.
ghci> createDirectory "/tmp/mydir" ghci> getDirectoryFiles "/tmp/mydir" [".",".."] ghci> createDirectory "/tmp/mydir/anotherdir" ghci> getDirectoryFiles "/tmp/mydir" [".","..","anotherdir"]
createDirectoryIfMissing Source #
:: Bool | Create parent directories or not |
-> RawFilePath | The path of the directory to create |
-> IO () |
Create a new directory if it does not already exist. If the first
argument is True
the function will also create all parent directories
when they are missing.
removeFile :: RawFilePath -> IO () Source #
Remove a file. This function internally calls unlink
. If the file does
not exist, an exception is thrown.
tryRemoveFile :: RawFilePath -> IO () Source #
A function that "tries" to remove a file. If the file does not exist, nothing happens.
removeDirectory :: RawFilePath -> IO () Source #
Remove a directory. The target directory needs to be empty; Otherwise an exception will be thrown.
removeDirectoryRecursive :: RawFilePath -> IO () Source #
Remove an existing directory dir together with its contents and subdirectories. Within this directory, symbolic links are removed without affecting their targets.