Copyright | (c) Sergey Vinokurov 2024 |
---|---|
License | Apache-2.0 (see LICENSE) |
Maintainer | serg.foo@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
You’ll most likely be interested in either
getDirectoryContentsRecursive
to search directory hierarchy recursivelyDirStream
,openDirStream
,readDirStream
, andcloseDirStream
to traverse single directory efficiently
Synopsis
- data DirStream
- openDirStream :: OsPath -> IO DirStream
- readDirStream :: DirStream -> IO (Maybe (OsPath, FileType))
- closeDirStream :: DirStream -> IO ()
- data SymlinkType
- data FileType
- newtype Basename a = Basename {
- unBasename :: a
- getFileType :: OsPath -> IO FileType
- getDirectoryContentsRecursive :: OsPath -> IO [(OsPath, FileType)]
- listContentsRecFold :: forall f a b. (Foldable f, Coercible b OsPath) => Maybe Int -> (forall c. OsPath -> b -> Relative OsPath -> Basename OsPath -> SymlinkType -> (a -> IO c -> IO c) -> (IO c -> IO c) -> IO c -> IO c) -> (OsPath -> b -> Relative OsPath -> Basename OsPath -> FileType -> IO (Maybe a)) -> f b -> IO [a]
- regularFile :: FileType
- regularDirectory :: FileType
- regularOther :: FileType
- symlinkFile :: FileType
- symlinkDirectory :: FileType
- symlinkOther :: FileType
Documentation
Abstract handle to directory contents.
May be closed multiple times and will be automatically closed by GC when it goes out of scope.
closeDirStream :: DirStream -> IO () Source #
Deallocate directory handle. It’s safe to close DirStream
multiple times,
unlike the underlying OS-specific directory stream handle.
File types
data SymlinkType Source #
Instances
Instances
Generic FileType Source # | |
Read FileType Source # | |
Show FileType Source # | |
NFData FileType Source # | |
Defined in System.Directory.OsPath.Types | |
Eq FileType Source # | |
Ord FileType Source # | |
Defined in System.Directory.OsPath.Types | |
type Rep FileType Source # | |
Defined in System.Directory.OsPath.Types type Rep FileType = D1 ('MetaData "FileType" "System.Directory.OsPath.Types" "directory-ospath-streaming-0.2-7RVORjIhdhMHkPO5xAl8fN" 'False) (C1 ('MetaCons "File" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 SymlinkType)) :+: (C1 ('MetaCons "Directory" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 SymlinkType)) :+: C1 ('MetaCons "Other" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 SymlinkType)))) |
Basename part of filename, without directory separators.
Basename | |
|
Instances
Get directory contents
getDirectoryContentsRecursive :: OsPath -> IO [(OsPath, FileType)] Source #
Recursively list all the files and directories in a directory and all subdirectories.
The directory structure is traversed depth-first.
The result is generated lazily so is not well defined if the source directory structure changes before the list is fully consumed.
Symlinks within directory structure may cause result to be infinitely long.
:: forall f a b. (Foldable f, Coercible b OsPath) | |
=> Maybe Int | Depth limit if specified, negative values treated the same as positive ones. |
-> (forall c. OsPath -> b -> Relative OsPath -> Basename OsPath -> SymlinkType -> (a -> IO c -> IO c) -> (IO c -> IO c) -> IO c -> IO c) | Decide how to fold directory and its children given its path. Can do IO actions to plan what to do and typically should derive its
result from last Returns Arguments:
The passed |
-> (OsPath -> b -> Relative OsPath -> Basename OsPath -> FileType -> IO (Maybe a)) | What to do with file |
-> f b | Roots to search in, either absolute or relative |
-> IO [a] |
The most general form of gathering directory contents.
Treats symlinks the same as regular files and directories. Folding functions can decide how to handle symlinks.
Both directory and file actions can throw exceptions and this function will try to close finished directory streams promptly (they’ll be closed by GC in the worst case).
Utilities
regularFile :: FileType Source #
Auxiliary constants to refer to different file types without allocations.
regularDirectory :: FileType Source #
Auxiliary constants to refer to different file types without allocations.
regularOther :: FileType Source #
Auxiliary constants to refer to different file types without allocations.
symlinkFile :: FileType Source #
Auxiliary constants to refer to different file types without allocations.
symlinkDirectory :: FileType Source #
Auxiliary constants to refer to different file types without allocations.
symlinkOther :: FileType Source #
Auxiliary constants to refer to different file types without allocations.