Module: System.FilePath
Table of Contents
1 System.FilePath
A library for FilePath manipulations, using Posix style paths on all platforms. Importing System.FilePath is usually better. (Documentation)
Examples:
>>> import qualified System.FilePath as SF >>> import System.FilePath ((<.>), (</>)) >>> >>> -- Type tab to complete -- >>> SF. SF.-<.> SF.hasTrailingPathSeparator SF.replaceExtension SF.<.> SF.isAbsolute SF.replaceFileName SF.</> SF.isDrive SF.searchPathSeparator SF.FilePath SF.isExtSeparator SF.splitDirectories SF.addExtension SF.isPathSeparator SF.splitDrive SF.addTrailingPathSeparator SF.isRelative SF.splitExtension SF.combine SF.isSearchPathSeparator SF.splitExtensions SF.dropDrive SF.isValid SF.splitFileName SF.dropExtension SF.joinDrive SF.splitPath SF.dropExtensions SF.joinPath SF.splitSearchPath SF.dropFileName SF.makeRelative SF.takeBaseName SF.dropTrailingPathSeparator SF.makeValid SF.takeDirectory SF.equalFilePath SF.normalise SF.takeDrive SF.extSeparator SF.pathSeparator SF.takeExtension SF.getSearchPath SF.pathSeparators SF.takeExtensions SF.hasDrive SF.replaceBaseName SF.takeFileName SF.hasExtension SF.replaceDirectory >>> >>> :info SF.FilePath type FilePath = String -- Defined in ‘GHC.IO’ >>> >>> SF.pathSeparator '/' >>> >>> SF.pathSeparators "/" >>> >>> SF.splitExtension "/boot/grub/grub.cfg" ("/boot/grub/grub",".cfg") >>> >>> SF.takeExtension "/boot/grub/grub.cfg" ".cfg" >>> >>> SF.takeExtension "/boot/grub/grub" "" >>> >>> SF.replaceExtension "/boot/grub/grub.cfg" ".bin" "/boot/grub/grub.bin" >>> >>> SF.replaceExtension "/boot/grub/grub" ".bin" "/boot/grub/grub.bin" >>> >>> SF.replaceExtension "/boot/grub/grub.tar.gz" ".bin" "/boot/grub/grub.tar.bin" >>> >>> SF.dropExtension "/boot/grub/grub.cfg" "/boot/grub/grub" >>> >>> SF.hasExtension "/boot/grub/grub.cfg" True >>> SF.hasExtension "/boot/grub/grub" False >>> -- Add an extension, even if there is already one there, equivalent -- to addExtension. -- >>> "/etc/grub" <.> ".cfg" "/etc/grub.cfg" >>> >>> SF.takeFileName "/boot/grub/grub.cfg" "grub.cfg" >>> >>> SF.replaceFileName "/boot/grub/grub.cfg" "dummy.tar.gz" "/boot/grub/dummy.tar.gz" >>> >>> SF.dropFileName "/boot/grub/grub.cfg" "/boot/grub/" >>> >>> SF.takeBaseName "/boot/grub/grub.cfg" "grub" >>> -- Get the directory name, move up one level. -- >>> SF.takeDirectory "/boot/grub/grub.cfg" "/boot/grub" >>> >>> SF.takeDirectory "~" "." >>> SF.takeDirectory "/" "/" >>> SF.takeDirectory "." "." >>> SF.takeDirectory ".." "." >>> -- Set the directory, keeping the filename the same. -- >>> SF.replaceDirectory "/boot/grub/grub.cfg" "~" "~/grub.cfg" >>> -- Join Path -- >>> SF.combine "/boot/" "grub/grub.cfg" "/boot/grub/grub.cfg" >>> >>> SF.combine "/boot/" "/grub/grub.cfg" "/grub/grub.cfg" >>> >>> SF.combine "/boot" "grub/grub.cfg" "/boot/grub/grub.cfg" >>> -- Operator to Join Path -- >>> :t (</>) (</>) :: FilePath -> FilePath -> FilePath >>> >>> "/boot" </> "grub/grub.cfg" "/boot/grub/grub.cfg" >>> >>> SF.splitPath "/boot/grub/grub.cfg" ["/","boot/","grub/","grub.cfg"] >>> >>> SF.joinPath ["/","boot/","grub/","grub.cfg"] "/boot/grub/grub.cfg" >>> >>> SF.splitDrive "/boot/grub/grub.cfg" ("/","boot/grub/grub.cfg") >>> -- (Running in Linux) -- >>> SF.splitDrive "C:\\boot\\grub\\grub.cfg" ("","C:\\boot\\grub\\grub.cfg") >>>