A Path is the name of a file or some other resource.
The path mechanism provides a layer of abstraction, so you can
use the same functions on either a filename or a URL/URI.
Functions that in standard Scheme take a filename
have been generalized to take a path or a path string,
as if using the path function below. For example:
(open-input-file "http://www.gnu.org/index.html") (open-input-file (URI "ftp://ftp.gnu.org/README"))
Type: path
A general path, which can be a
filenameor aURI. It can be either afilenameor aURI. Represented using the abstract Java classgnu.kawa.io.Path.Coercing a value to a
Pathis equivalent to calling thepathconstructor documented below.
Constructor: path arg
Coerces the
argto apath. Ifargis already apath, it is returned unchanged. Ifargis ajava.net.URI, or ajava.net.URLthen aURIvalue is returned. Ifargis ajava.io.File, afilepathvalue is returned. Otherwise,argcan be a string. AURIvalue is returned if the string starts with a URI scheme (such as"http:"), and afilepathvalue is returned otherwise.
Predicate: path? arg
True if
argis apath- i.e. an instance of agnu.kawa.io.Path.
Procedure: current-path [new-value]
With no arguments, returns the default directory of the current thread as a
path. This is used as the base directory for relative pathnames. The initial value is that of theuser.dirproperty as returned by(java.lang.System:getProperty "user.dir").If a
new-valueargument is given, sets the default directory:(current-path "/opt/myApp/")A string value is automatically converted to a
path, normally afilepath.Alternatively, you can change the default using a setter:
(set! (current-path) "/opt/myApp/")Since
current-pathis a parameter object, you can locally change the value usingparameterize.
Type: filepath
The name of a local file. Represented using the Java class
gnu.kawa.io.FilePath, which is a wrapper aroundjava.io.File.
Predicate: filepath? arg
True if
argis afilepath- i.e. an instance of agnu.kawa.io.FilePath.
Type: URI
A Uniform Resource Indicator, which is a generalization of the more familiar URL. The general format is specified by RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax. Represented using the Java class
gnu.kawa.io.URIPath, which is a wrapper aroundjava.net.URI. A URI can be a URL, or it be a relative URI.
Predicate: URI? arg
True if
argis aURI- i.e. an instance of agnu.kawa.io.URIPath.
Type: URL
A Uniform Resource Locator - a subtype of
URI. Represented using the Java classgnu.kawa.io.URLPath, which is a wrapper around ajava.net.URL, in addition to extendinggnu.kawa.io.URIPath.
Procedure: path-scheme arg
Returns the "URI scheme" of
arg(coerced to apath) if it is defined, or#fotherwise. The URI scheme of afilepathis"file"if thefilepathis absolute, and#fotherwise.(path-scheme "http://gnu.org/") ⇒ "http"
Procedure: path-authority arg
Returns the authority part of
arg(coerced to apath) if it is defined, or#fotherwise. The "authority" is usually the hostname, but may also include user-info or a port-number.(path-authority "http://me@localhost:8000/home") ⇒ "me@localhost:8000"
Procedure: path-host arg
Returns the name name part of
arg(coerced to apath) if it is defined, or#fotherwise.(path-host "http://me@localhost:8000/home") ⇒ "localhost"
Procedure: path-user-info arg
Returns the "user info" of
arg(coerced to apath) if it is specified, or#fotherwise.(path-host "http://me@localhost:8000/home") ⇒ "me"
Procedure: path-port arg
Returns the port number of
arg(coerced to apath) if it is specified, or-1otherwise. Even if there is a default port associated with a URI scheme (such as 80 forhttp), the value -1 is returned unless the port number is explictly specified.(path-host "http://me@localhost:8000/home") ⇒ 8000 (path-host "http://me@localhost/home") ⇒ -1
Procedure: path-file arg
Returns the "path component" of the
arg(coerced to apath). (The namepath-pathmight be more logical, but it is obviously a bit awkward.) The path component of a file name is the file name itself. For a URI, it is the main hierarchical part of the URI, without schema, authority, query, or fragment.(path-file "http://gnu.org/home/me.html?add-bug#body") ⇒ "/home/me.html"
Procedure: path-directory arg
If
arg(coerced to apath) is directory, returnarg; otherwise return the "parent" path, without the final component.(path-directory "http://gnu.org/home/me/index.html#body") ⇒ (path "http://gnu.org/home/me/") (path-directory "http://gnu.org/home/me/") ⇒ (path "http://gnu.org/home/me/")
(path-directory "./dir")⇒(path "./dir")ifdiris a directory, and(path ".")otherwise.
Procedure: path-parent arg
Returns the "parent directory" of
arg(coerced to apath). Ifargis not a directory, same aspath-directory.arg(path-parent "a/b/c") ⇒ (path "a/b") (path-parent "file:/a/b/c") ⇒ (path "file:/a/b/c") (path-parent "file:/a/b/c/") ⇒ (path "file:/a/b/")
Procedure: path-last arg
The last component of path component of
arg(coerced to apath). Returns a substring of(path-file. If that string ends with ‘arg)/’ or the path separator, that last character is ignored. Returns the tail of the path-string, following the last (non-final) ‘/’ or path separator.(path-last "http:/a/b/c") ⇒ "c" (path-last "http:/a/b/c/") ⇒ "c" (path-last "a/b/c") ⇒ "c"
Procedure: path-extension arg
Returns the "extension" of the
arg(coerced to apath).(path-extension "http://gnu.org/home/me.html?add-bug#body") ⇒ "html" (path-extension "/home/.init") ⇒ #f
Procedure: path-query arg
Returns the query part of
arg(coerced to apath) if it is defined, or#fotherwise. The query part of a URI is the part after ‘?’.(path-query "http://gnu.org/home?add-bug") ⇒ "add-bug"
Procedure: path-fragment arg
Returns the fragment part of
arg(coerced to apath) if it is defined, or#fotherwise. The fragment of a URI is the part of after ‘#’.(path-query "http://gnu.org/home#top") ⇒ "top"
Procedure: resolve-uri uri base
Returns a
uriunchanged if it is an absolute URI. Otherwise resolves it against a base URIbase, which is normally (though not always) absolute.This uses the algorithm specifyed by RFC-3986 (assuming
baseis absolute), unlike the obsolete RFC-2396 algorithm used byjava.net.URI.resolve.