[[a]] -> [a] +filepath
Join path elements back together.
> Valid x => joinPath (splitPath x) == x
> joinPath [] == ""
> Posix: joinPath ["test","file","path"] == "test/file/path"
Add a trailing file path separator if one is not already present.
> hasTrailingPathSeparator (addTrailingPathSeparator x)
> hasTrailingPathSeparator x ==> addTrailingPathSeparator x == x
> Posix: addTrailingPathSeparator "test/rest" == "test/rest/"
Delete the drive, if it exists.
> dropDrive x == snd (splitDrive x)
Remove last extension, and the "." preceding it.
> dropExtension x == fst (splitExtension x)
Drop all extensions
> not $ hasExtension (dropExtensions x)
Drop the filename.
> dropFileName x == fst (splitFileName x)
Remove any trailing path separators
> dropTrailingPathSeparator "file/test/" == "file/test"
> Posix: not (hasTrailingPathSeparator (dropTrailingPathSeparator x)) || isDrive x
> Posix: dropTrailingPathSeparator "/" == "/"
> Windows: dropTrailingPathSeparator "\\" == "\\"
Take a FilePath and make it valid; does not change already valid FilePaths.
> isValid (makeValid x)
> isValid x ==> makeValid x == x
> makeValid "" == "_"
> Windows: makeValid "c:\\test:of_test" == "c:\\test_of_test"
> Windows: makeValid "test*" == "test_"
> Windows: makeValid "c:\\test\\nul" == "c:\\test\\nul_"
> Windows: makeValid "c:\\test\\prn.txt" == "c:\\test\\prn_.txt"
> Windows: makeValid "c:\\test/prn.txt" == "c:\\test/prn_.txt"
> Windows: makeValid "c:\\nul\\file" == "c:\\nul_\\file"
Normalise a file
* // outside of the drive can be made blank
* / -> pathSeparator
* ./ -> ""
> Posix: normalise "/file/\\test////" == "/file/\\test/"
> Posix: normalise "/file/./test" == "/file/test"
> Posix: normalise "/test/file/../bob/fred/" == "/test/file/../bob/fred/"
> Posix: normalise "../bob/fred/" == "../bob/fred/"
> Posix: normalise "./bob/fred/" == "bob/fred/"
> Windows: normalise "c:\\file/bob\\" == "C:\\file\\bob\\"
> Windows: normalise "c:\\" == "C:\\"
> Windows: normalise "\\\\server\\test" == "\\\\server\\test"
> Windows: normalise "c:/file" == "C:\\file"
> normalise "." == "."
> Posix: normalise "./" == "./"
> Posix: normalise "./." == "./"
> Posix: normalise "/" == "/"
> Posix: normalise "bob/fred/." == "bob/fred/"
Get the directory name, move up one level.
> takeDirectory x `isPrefixOf` x || takeDirectory x == "."
> takeDirectory "foo" == "."
> takeDirectory "/foo/bar/baz" == "/foo/bar"
> takeDirectory "/foo/bar/baz/" == "/foo/bar/baz"
> takeDirectory "foo/bar/baz" == "foo/bar"
> Windows: takeDirectory "foo\\bar" == "foo"
> Windows: takeDirectory "foo\\bar\\\\" == "foo\\bar"
> Windows: takeDirectory "C:\\" == "C:\\"
Get the drive from a filepath.
> takeDrive x == fst (splitDrive x)
Get the file name.
> takeFileName "test/" == ""
> takeFileName x `isSuffixOf` x
> takeFileName x == snd (splitFileName x)
> Valid x => takeFileName (replaceFileName x "fred") == "fred"
> Valid x => takeFileName (x </> "fred") == "fred"
> Valid x => isRelative (takeFileName x)
Get the base name, without an extension or path.
> takeBaseName "file/test.txt" == "test"
> takeBaseName "dave.ext" == "dave"
> takeBaseName "" == ""
> takeBaseName "test" == "test"
> takeBaseName (addTrailingPathSeparator x) == ""
> takeBaseName "file/file.tar.gz" == "file.tar"
Get the extension of a file, returns "" for no extension, .ext otherwise.
> takeExtension x == snd (splitExtension x)
> Valid x => takeExtension (addExtension x "ext") == ".ext"
> Valid x => takeExtension (replaceExtension x "ext") == ".ext"
Get all extensions
> takeExtensions "file.tar.gz" == ".tar.gz"
Combine two paths, if the second path isAbsolute, then it returns the second.
> Valid x => combine (takeDirectory x) (takeFileName x) `equalFilePath` x
> Posix: combine "/" "test" == "/test"
> Posix: combine "home" "bob" == "home/bob"
> Windows: combine "home" "bob" == "home\\bob"
> Windows: combine "home" "/bob" == "/bob"
Join a drive and the rest of the path.
> uncurry joinDrive (splitDrive x) == x
> Windows: joinDrive "C:" "foo" == "C:foo"
> Windows: joinDrive "C:\\" "bar" == "C:\\bar"
> Windows: joinDrive "\\\\share" "foo" == "\\\\share\\foo"
> Windows: joinDrive "/:" "foo" == "/:\\foo"
Contract a filename, based on a relative path.
There is no corresponding makeAbsolute function, instead use System.Directory.canonicalizePath which has the same effect.
> Valid y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
> makeRelative x x == "."
> null y || equalFilePath (makeRelative x (x </> y)) y || null (takeFileName x)
> Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
> Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
> Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
> Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
> Windows: makeRelative "/Home" "/home/bob" == "bob"
> Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
> Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
> Posix: makeRelative "/fred" "bob" == "bob"
> Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
> Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
> Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"
Alias to addExtension, for people who like that sort of thing.
Show more results