System.Posix.Directory.Traversals

posix-paths-0.3.0.0: POSIX filepath/directory functionality

Safe Haskell | None
Language | Haskell2010

System.Posix.Directory.Traversals

Synopsis

- getDirectoryContents :: RawFilePath -> IO [(DirType, RawFilePath)]
- traverseDirectoryContents :: MonadUnliftIO m => (s -> (DirType, RawFilePath) -> m s) -> s -> RawFilePath -> m s
- allDirectoryContents :: RawFilePath -> IO [RawFilePath]
- allDirectoryContents' :: RawFilePath -> IO [RawFilePath]
- traverseDirectory :: MonadUnliftIO m => (s -> RawFilePath -> m s) -> s -> RawFilePath -> m s
- readDirEnt :: DirStream -> IO (DirType, RawFilePath)
- packDirStream :: Ptr CDir -> DirStream
- unpackDirStream :: DirStream -> Ptr CDir
- realpath :: RawFilePath -> IO RawFilePath

# Documentation

getDirectoryContents :: RawFilePath -> IO [(DirType, RawFilePath)] #

traverseDirectoryContents :: MonadUnliftIO m => (s -> (DirType, RawFilePath) -> m s) -> s -> RawFilePath -> m s #

Apply the `action` to the given directory (must be a directory), without recursing into subdirectories.

This function does filter out the `.` and `..` entries.

Emitted file paths are the directory entry names, thus not prefixed with the given parent directory.

This function allows for memory-efficient traversals.

Use this if you want to implement your own recursive subdirectory traversal, deciding e.g. into which directories or symlinks to traverse.

You SHOULD check if the obtained `DirType` is `dtUnknown` (see comments in `man 3 readdir` on `d_type`), and do a `getFileStatus` in that case (results in `stat()`), as not all file systems implement obtaining a `DirType`.

allDirectoryContents :: RawFilePath -> IO [RawFilePath] #

Get all files from a directory and its subdirectories.

Upon entering a directory, `allDirectoryContents` will get all entries strictly. However the returned list is lazy in that directories will only be accessed on demand.

allDirectoryContents' :: RawFilePath -> IO [RawFilePath] #

Get all files from a directory and its subdirectories strictly.

traverseDirectory :: MonadUnliftIO m => (s -> RawFilePath -> m s) -> s -> RawFilePath -> m s #

Recursively apply the `action` to the parent file or directory and all files/subdirectories.

Like UNIX `find`, this includes the parent file/directory!

As for `find`, emitted file paths of subdirectories contain slashes, starting with the parent directory.

This function allows for memory-efficient traversals.

readDirEnt :: DirStream -> IO (DirType, RawFilePath) #

packDirStream :: Ptr CDir -> DirStream #

unpackDirStream :: DirStream -> Ptr CDir #

realpath :: RawFilePath -> IO RawFilePath #

return the canonicalized absolute pathname

like canonicalizePath, but uses realpath(3)