Copyright | Copyright (C) 2004-2011 John Goerzen |
---|---|
License | BSD3 |
Maintainer | John Goerzen <jgoerzen@complete.org> |
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
This module provides various helpful utilities for dealing with path and file names, directories, and related support.
Written by John Goerzen, jgoerzen@complete.org
- splitExt :: String -> (String, String)
- absNormPath :: String -> String -> Maybe String
- secureAbsNormPath :: String -> String -> Maybe String
- recurseDir :: HVFS a => a -> FilePath -> IO [FilePath]
- recurseDirStat :: HVFS a => a -> FilePath -> IO [(FilePath, HVFSStatEncap)]
- recursiveRemove :: HVFS a => a -> FilePath -> IO ()
- bracketCWD :: FilePath -> IO a -> IO a
- mktmpdir :: String -> IO String
- brackettmpdir :: String -> (String -> IO a) -> IO a
- brackettmpdirCWD :: String -> IO a -> IO a
Name processing
splitExt :: String -> (String, String) Source #
Splits a pathname into a tuple representing the root of the name and the extension. The extension is considered to be all characters from the last dot after the last slash to the end. Either returned string may be empty.
:: String | Absolute path for use with starting directory |
-> String | The path name to make absolute |
-> Maybe String | Result |
Make an absolute, normalized version of a path with all double slashes, dot, and dotdot entries removed.
The first parameter is the base for the absolut calculation; in many cases, it would correspond to the current working directory.
The second parameter is the pathname to transform. If it is already absolute, the first parameter is ignored.
Nothing may be returned if there's an error; for instance, too many ..
entries
for the given path.
:: String | Absolute path for use with starting directory |
-> String | The path to make absolute |
-> Maybe String |
Like absNormPath, but returns Nothing if the generated result is not the passed base path or a subdirectory thereof.
Directory Processing
recurseDir :: HVFS a => a -> FilePath -> IO [FilePath] Source #
Obtain a recursive listing of all files/directories beneath the specified directory. The traversal is depth-first and the original item is always present in the returned list.
If the passed value is not a directory, the return value be only that value.
The "." and ".." entries are removed from the data returned.
recurseDirStat :: HVFS a => a -> FilePath -> IO [(FilePath, HVFSStatEncap)] Source #
Like recurseDir
, but return the stat() (System.Posix.Files.FileStatus)
information with them. This is an optimization if you will be statting files
yourself later.
The items are returned lazily.
WARNING: do not change your current working directory until you have consumed all the items. Doing so could cause strange effects.
Alternatively, you may wish to pass an absolute path to this function.
recursiveRemove :: HVFS a => a -> FilePath -> IO () Source #
Removes a file or a directory. If a directory, also removes all its child files/directories.
bracketCWD :: FilePath -> IO a -> IO a Source #
Changes the current working directory to the given path, executes the given I/O action, then changes back to the original directory, even if the I/O action raised an exception.
Temporary Directories
mktmpdir :: String -> IO String Source #
Creates a temporary directory for your use.
The passed string should be a template suitable for mkstemp; that is, end with
"XXXXXX"
.
Your string should probably start with the value returned from System.Directory.getTemporaryDirectory.
The name of the directory created will be returned.