Copyright | (c) 2019-2020 Vaclav Svejcar |
---|---|
License | BSD-3-Clause |
Maintainer | vaclav.svejcar@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Module providing functions for working with the local file system, its file and directories.
Synopsis
- type CreateDirectoryFn m = FilePath -> m ()
- type DoesFileExistFn m = FilePath -> m Bool
- type FindFilesFn m = FilePath -> (FilePath -> Bool) -> m [FilePath]
- type FindFilesByExtsFn m = FilePath -> [Text] -> m [FilePath]
- type FindFilesByTypesFn m = CtHeadersConfig -> [FileType] -> FilePath -> m [FilePath]
- type GetCurrentDirectoryFn m = m FilePath
- type ListFilesFn m = FilePath -> m [FilePath]
- type LoadFileFn m = FilePath -> m Text
- data FileSystem m = FileSystem {}
- mkFileSystem :: MonadIO m => FileSystem m
- findFiles :: MonadIO m => FindFilesFn m
- findFilesByExts :: MonadIO m => FindFilesByExtsFn m
- findFilesByTypes :: MonadIO m => FindFilesByTypesFn m
- listFiles :: MonadIO m => ListFilesFn m
- loadFile :: MonadIO m => LoadFileFn m
- fileExtension :: FilePath -> Maybe Text
- excludePaths :: [Regex] -> [FilePath] -> [FilePath]
Type Aliases
type CreateDirectoryFn m Source #
= FilePath | path of new directory |
-> m () | IO action result |
Type of a function that creates new empty directory on the given path.
type DoesFileExistFn m Source #
type FindFilesFn m Source #
Type of a function that recursively finds files on given path whose filename matches the predicate.
type FindFilesByExtsFn m Source #
= FilePath | path to search |
-> [Text] | list of file extensions (without dot) |
-> m [FilePath] | list of found files |
Type of a function that recursively finds files on given path by file extensions.
type FindFilesByTypesFn m Source #
= CtHeadersConfig | configuration of license headers |
-> [FileType] | list of file types |
-> FilePath | path to search |
-> m [FilePath] | list of found files |
Type of a function that recursively find files on given path by their file types.
type GetCurrentDirectoryFn m = m FilePath Source #
Type of a function that obtains the current working directory as an absolute path.
type ListFilesFn m Source #
Type of a function that recursively find all files on given path. If file reference is passed instead of directory, such file path is returned.
type LoadFileFn m Source #
Type of a function that loads file content in UTF8 encoding.
Polymorphic Record
data FileSystem m Source #
Polymorphic record composed of file system IO function types, allowing to abstract over concrete implementation. Whenever you need to use effectful functions from this module, consider using this record instead of using them directly, as it allows you to use different records for production code and for testing, which is not as easy if you wire some of the provided functions directly.
FileSystem | |
|
Instances
Has (FileSystem (RIO Env)) Env Source # | |
Defined in Headroom.Command.Init |
mkFileSystem :: MonadIO m => FileSystem m Source #
Creates new FileSystem
that performs actual disk IO operations.
Traversing the File System
findFiles :: MonadIO m => FindFilesFn m Source #
Recursively finds files on given path whose filename matches the predicate.
findFilesByExts :: MonadIO m => FindFilesByExtsFn m Source #
Recursively finds files on given path by file extensions.
findFilesByTypes :: MonadIO m => FindFilesByTypesFn m Source #
Recursively find files on given path by their file types.
listFiles :: MonadIO m => ListFilesFn m Source #
Recursively find all files on given path. If file reference is passed instead of directory, such file path is returned.
loadFile :: MonadIO m => LoadFileFn m Source #
Loads file content in UTF8 encoding.
Working with Files Metadata
Returns file extension for given path (if file), or nothing otherwise.
>>>
fileExtension "path/to/some/file.txt"
Just "txt"
Other
:: [Regex] | patterns describing paths to exclude |
-> [FilePath] | list of file paths |
-> [FilePath] | resulting list of file paths |
Takes list of patterns and file paths and returns list of file paths where those matching the given patterns are excluded.
>>>
import Headroom.Data.Regex (re)
>>>
:set -XQuasiQuotes
>>>
excludePaths [[re|\.hidden|], [re|zzz|]] ["foo/.hidden", "test/bar", "x/zzz/e"]
["test/bar"]