hmt-base-0.20: Haskell Music Theory Base
Safe HaskellSafe-Inferred
LanguageHaskell2010

Music.Theory.Directory

Description

Directory functions.

Synopsis

Documentation

parent_dir :: FilePath -> FilePath Source #

takeDirectory gives different answers depending on whether there is a trailing separator.

x = ["x/y","x/y/","x","/"]
map parent_dir x == ["x","x",".","/"]
map takeDirectory x == ["x","x/y",".","/"]

path_split :: String -> [FilePath] Source #

Colon separated path list.

path_from_env :: String -> IO [FilePath] Source #

Read environment variable and split path. Error if enviroment variable not set.

path_from_env "PATH"
path_from_env "NONPATH" -- error

path_recursive :: [FilePath] -> IO [FilePath] Source #

Expand a path to include all subdirectories recursively.

p = ["/home/rohan/sw/hmt-base/Music", "/home/rohan/sw/hmt/Music"]
r <- path_recursive p
length r == 44

path_scan :: [FilePath] -> FilePath -> IO (Maybe FilePath) Source #

Scan a list of directories until a file is located, or not. Stop once a file is located, do not traverse any sub-directory structure.

mapM (path_scan ["/sbin","/usr/bin"]) ["fsck","ghc"]

path_scan_err :: [FilePath] -> FilePath -> IO FilePath Source #

Erroring variant.

path_search :: [FilePath] -> FilePath -> IO [FilePath] Source #

Scan a list of directories and return all located files. Do not traverse any sub-directory structure. Since 1.2.1.0 there is also findFiles.

let path = ["/home/rohan/sw/hmt-base","/home/rohan/sw/hmt"]
path_search path "README.md"
findFiles path "README.md"

dir_list_ext :: FilePath -> String -> IO [FilePath] Source #

Get sorted list of files at dir with ext, ie. ls dir/*.ext

dir_list_ext "/home/rohan/rd/j/" ".hs"

dir_list_ext_path :: FilePath -> String -> IO [FilePath] Source #

Post-process dir_list_ext to gives file-names with dir prefix.

dir_list_ext_path "/home/rohan/rd/j/" ".hs"

dir_subset_rel :: [String] -> FilePath -> IO [FilePath] Source #

Subset of files in dir with an extension in ext. Extensions include the leading dot and are case-sensitive. Results are relative to dir.

dir_subset :: [String] -> FilePath -> IO [FilePath] Source #

Variant of dir_subset_rel where results have dir/ prefix.

dir_subset [".hs"] "/home/rohan/sw/hmt/cmd"

dir_subdirs_rel :: FilePath -> IO [FilePath] Source #

Subdirectories (relative) of dir.

dir_subdirs :: FilePath -> IO [FilePath] Source #

Subdirectories of dir.

dir_subdirs_recursively :: FilePath -> IO [FilePath] Source #

Recursive form of dir_subdirs.

dir_subdirs_recursively "/home/rohan/sw/hmt-base/Music"

to_absolute_cwd :: FilePath -> IO FilePath Source #

If path is not absolute, prepend current working directory.

to_absolute_cwd "x"

if_file_exists :: (FilePath, IO t, IO t) -> IO t Source #

If i is an existing file then j else k.

writeFile_mkdir_x :: FilePath -> String -> IO () Source #

writeFile_mkdir only if file does not exist.