System.Directory module provides
makeAbsolute function, which convert path to absolute path. If the path is
relative to current directory then t he current directory is prepended and
then the combined result is normalised. If the path is already absolute, the
path is simply normalised.
This operation may fail with following
errors.
Error
|
Description
|
HardwareFault
|
A physical I/O error has occurred.
|
isDoesNotExistError or NoSuchThing
|
There is no path referring to the
working directory.
|
isPermissionError or PermissionDenied
|
The process has insufficient
privileges to perform the operation.
|
ResourceExhausted
|
Insufficient resources are available
to perform the operation.
|
UnsupportedOperation
|
The operating system has no notion of
current working directory.
|
Following is the signature of normalize
function. ‘normalise’ function is available at System.FilePath module.
Prelude System.FilePath> :t normalise
normalise :: FilePath -> FilePath
Following are the rules for normalize
function , which normalizes a file path.
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 "C:.\\" == "C:" Windows: normalise "\\\\server\\test" == "\\\\server\\test" Windows: normalise "//server/test" == "\\\\server\\test" Windows: normalise "c:/file" == "C:\\file" Windows: normalise "/file" == "\\file" Windows: normalise "\\" == "\\" Windows: normalise "/./" == "\\" normalise "." == "." Posix: normalise "./" == "./" Posix: normalise "./." == "./" Posix: normalise "/./" == "/" Posix: normalise "/" == "/" Posix: normalise "bob/fred/." == "bob/fred/" Posix: normalise "//home" == "/home"
Prelude System.Directory> makeAbsolute "." "/Users/harikrishna_gurram" Prelude System.Directory> Prelude System.Directory> makeAbsolute ".." "/Users/harikrishna_gurram/.." Prelude System.Directory> Prelude System.Directory> makeAbsolute ".//Shared" "/Users/harikrishna_gurram/Shared" Prelude System.Directory> Prelude System.Directory> makeAbsolute ".\\Shared" "/Users/harikrishna_gurram/.\\Shared" Prelude System.Directory> Prelude System.Directory> makeAbsolute ".////Shared" "/Users/harikrishna_gurram/Shared" Prelude System.Directory> Prelude System.Directory> makeAbsolute ".////////Shared" "/Users/harikrishna_gurram/Shared" Prelude System.Directory> Prelude System.Directory> makeAbsolute ".///Shared" "/Users/harikrishna_gurram/Shared" Prelude System.Directory> Prelude System.Directory> makeAbsolute "/.///Shared" "/Shared" Prelude System.Directory> makeAbsolute "//.///Shared" "/Shared" Prelude System.Directory> makeAbsolute "///.///Shared" "/Shared" Prelude System.Directory>
No comments:
Post a Comment