Copyright | (c) XT 2016 |
---|---|
License | Apache 2.0 |
Maintainer | e@xtendo.org |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
Higher-level API for the RawFilePath
-variants of functions in the unix
module.
- type RawFilePath = ByteString
- callProcess :: RawFilePath -> [ByteString] -> IO ()
- callProcessSilent :: RawFilePath -> [ByteString] -> IO ExitCode
- readProcess :: RawFilePath -> [ByteString] -> IO ByteString
- readProcessEither :: RawFilePath -> [ByteString] -> IO (Either ByteString ByteString)
- listDirectory :: RawFilePath -> IO [RawFilePath]
- getDirectoryFiles :: RawFilePath -> IO [RawFilePath]
- getDirectoryFilesRecursive :: RawFilePath -> IO [RawFilePath]
- copyFile :: RawFilePath -> RawFilePath -> IO ()
- getHomeDirectory :: IO RawFilePath
- doesFileExist :: RawFilePath -> IO Bool
- doesDirectoryExist :: RawFilePath -> IO Bool
- setCurrentDirectory :: RawFilePath -> IO ()
- tryRemoveFile :: RawFilePath -> IO ()
Documentation
type RawFilePath = ByteString #
A literal POSIX file path
Process
:: RawFilePath | Command to run |
-> [ByteString] | Command arguments |
-> IO () |
Creates a new process to run the specified command with the given arguments, and waits for it to finish. Throws an exception if the process returns a nonzero exit code.
*System.RawFilePath> callProcess "ls" ["-a", "src"] . .. System
:: RawFilePath | Command to run |
-> [ByteString] | Command arguments |
-> IO ExitCode |
Same as callProcess
except the child process will share the parent's
stdout and stderr, meaning it won't print anything.
:: RawFilePath | Command to run |
-> [ByteString] | Command arguments |
-> IO ByteString | The output from the command |
Runs a command, reads its standard output strictly, blocking until the process terminates, and returns the output as ByteString
.
*System.RawFilePath> readProcess "date" ["+%s"] "1469999314\n"
:: RawFilePath | Command to run |
-> [ByteString] | Command arguments |
-> IO (Either ByteString ByteString) | Either the stedrr output from the command if it finished with a nonzero exit code, or the stdout data if it finished normally. |
A 'safer' approach to readProcess
. Depending on the exit status of
the process, this function will return output either from stderr or stdout.
*System.RawFilePath> readProcessEither "date" ["%s"] Left "date: invalid date \226\128\152%s\226\128\153\n" *System.RawFilePath> readProcessEither "date" ["+%s"] Right "1469999817\n"
Directory
:: 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 ".."
*System.RawFilePath> listDirectory "src" ["..","System","."]
:: 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 ".."
*System.RawFilePath> getDirectoryFiles "src" ["..","System","."]
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"]
:: RawFilePath | The source path |
-> RawFilePath | The destination path |
-> IO () |
Copy a file from the source path to the destination path.
getHomeDirectory :: IO RawFilePath Source #
Returns the current user's home directory.
doesFileExist :: RawFilePath -> IO Bool Source #
Returns True
if the argument file exists and is not a directory.
doesDirectoryExist :: RawFilePath -> IO Bool Source #
Returns True
if the argument file exists and is a directory.
setCurrentDirectory :: RawFilePath -> IO () Source #
Change the working directory to the given path.
tryRemoveFile :: RawFilePath -> IO () Source #
A function that "tries" to remove a file. If the file does not exist, nothing happens.