System.FilePattern.Directory (original) (raw)
Description
Optimised directory traversal using [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
values. All results are guaranteed to be sorted.
Case Sensitivity: these traversals are optimised to reduce the number of IO operations performed. In particular, if the relevant subdirectories can be determined in advance it will use [doesDirectoryExist](/package/directory-1.3.6.0/docs/System-Directory.html#v:doesDirectoryExist "System.Directory")
rather than [getDirectoryContents](/package/directory-1.3.6.0/docs/System-Directory.html#v:getDirectoryContents "System.Directory")
. However, on case-insensitive file systems, if there is a directory foo
, then doesDirectoryExist "FOO"
will report True
, but FOO
won't be a result returned by [getDirectoryContents](/package/directory-1.3.6.0/docs/System-Directory.html#v:getDirectoryContents "System.Directory")
, which may result in different search results depending on whether a certain optimisations kick in.
If these optimisation differences are absolutely unacceptable use [getDirectoryFilesIgnoreSlow](System-FilePattern-Directory.html#v:getDirectoryFilesIgnoreSlow "System.FilePattern.Directory")
. However, normally these differences are not a problem.
Synopsis
- type FilePattern = String
- getDirectoryFiles :: FilePath -> [FilePattern] -> IO [FilePath]
- getDirectoryFilesIgnore :: FilePath -> [FilePattern] -> [FilePattern] -> IO [FilePath]
- getDirectoryFilesIgnoreSlow :: FilePath -> [FilePattern] -> [FilePattern] -> IO [FilePath]
Documentation
type FilePattern = String Source #
A type synonym for file patterns, containing **
and *
. For the syntax and semantics of [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
see [?==](System-FilePattern.html#v:-63--61--61- "System.FilePattern")
.
Most [FilePath](/package/base-4.14.1.0/docs/System-IO.html#t:FilePath "System.IO")
values lacking literal .
and ..
components are suitable as [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
values which match only that specific file. On Windows \
is treated as equivalent to /
.
You can write [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
values as a literal string, or build them up using the operators <.>
and </>
(but be aware that "" `</>` "foo"
produces "./foo"
).
getDirectoryFiles :: FilePath -> [FilePattern] -> IO [FilePath] Source #
Get the files below a certain root that match any of the [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
values. Only matches files, not directories. Avoids traversing into directories that it can detect won't have any matches in.
getDirectoryFiles "myproject/src" ["/*.h","/*.c"]
If there are certain directories/files that should not be explored, use [getDirectoryFilesIgnore](System-FilePattern-Directory.html#v:getDirectoryFilesIgnore "System.FilePattern.Directory")
.
Warning: on case-insensitive file systems certain optimisations can cause surprising results. See the top of the module for details.
getDirectoryFilesIgnore :: FilePath -> [FilePattern] -> [FilePattern] -> IO [FilePath] Source #
Get the files below a certain root matching any of the first set of [FilePattern](System-FilePattern-Directory.html#t:FilePattern "System.FilePattern.Directory")
values, but don't return any files which match any ignore pattern (the final argument). Typically the ignore pattens will end with /**
, e.g. .git/**
.
getDirectoryFilesIgnore "myproject/src" ["/*.h","/*.c"] [".git/**"]
Warning: on case-insensitive file systems certain optimisations can cause surprising results. See the top of the module for details.