posixpath -- Python library reference
Next: pwd
Prev: posix
Up: UNIX Specific Services
Top: Top
8.2. Standard Module posixpath
This module implements some useful functions on POSIX pathnames.
Do not import this module directly. Instead, import the
module os
and use os.path
.
- basename (p) -- function of module posixpath
-
Return the base name of pathname
p.
This is the second half of the pair returned by
posixpath.split(p)
.
- commonprefix (list) -- function of module posixpath
-
Return the longest string that is a prefix of all strings in
list.
If
list
is empty, return the empty string (
''
).
- exists (p) -- function of module posixpath
-
Return true if
p
refers to an existing path.
- expanduser (p) -- function of module posixpath
-
Return the argument with an initial component of `~' or
`~user' replaced by that user's home directory. An
initial `~' is replaced by the environment variable
$HOME
;
an initial `~user' is looked up in the password directory through
the built-in module pwd
. If the expansion fails, or if the
path does not begin with a tilde, the path is returned unchanged.
- expandvars (p) -- function of module posixpath
-
Return the argument with environment variables expanded. Substrings
of the form `$name' or `${name}' are
replaced by the value of environment variable name. Malformed
variable names and references to non-existing variables are left
unchanged.
- isabs (p) -- function of module posixpath
-
Return true if p is an absolute pathname (begins with a slash).
- isfile (p) -- function of module posixpath
-
Return true if p is an existing regular file. This follows
symbolic links, so both
islink()
and isfile()
can be true for the same
path.
- isdir (p) -- function of module posixpath
-
Return true if p is an existing directory. This follows
symbolic links, so both
islink()
and isdir()
can be true for the same
path.
- islink (p) -- function of module posixpath
-
Return true if
p
refers to a directory entry that is a symbolic link.
Always false if symbolic links are not supported.
- ismount (p) -- function of module posixpath
-
Return true if pathname p is a mount point: a point in a
file system where a different file system has been mounted. The
function checks whether p's parent, p/.., is on a
different device than p, or whether p/.. and
p point to the same i-node on the same device --- this should
detect mount points for all UNIX and POSIX variants.
- join (p, q) -- function of module posixpath
-
Join the paths
p
and
q intelligently:
If
q
is an absolute path, the return value is
q.
Otherwise, the concatenation of
p
and
q
is returned, with a slash (
'/'
) inserted unless
p
is empty or ends in a slash.
- normcase (p) -- function of module posixpath
-
Normalize the case of a pathname. This returns the path unchanged;
however, a similar function in
macpath
converts upper case to
lower case.
- samefile (p, q) -- function of module posixpath
-
Return true if both pathname arguments refer to the same file or directory
(as indicated by device number and i-node number).
Raise an exception if a stat call on either pathname fails.
- split (p) -- function of module posixpath
-
Split the pathname p in a pair
(head, tail)
, where
tail is the last pathname component and head is
everything leading up to that. If p ends in a slash (except if
it is the root), the trailing slash is removed and the operation
applied to the result; otherwise, join(head, tail)
equals
p. The tail part never contains a slash. Some boundary
cases: if p is the root, head equals p and
tail is empty; if p is empty, both head and
tail are empty; if p contains no slash, head is
empty and tail equals p.
- splitext (p) -- function of module posixpath
-
Split the pathname p in a pair
(root, ext)
such that root + ext == p
,
the last component of root contains no periods,
and ext is empty or begins with a period.
- walk (p, visit, arg) -- function of module posixpath
-
Calls the function visit with arguments
(arg, dirname, names)
for each directory in the
directory tree rooted at p (including p itself, if it is a
directory). The argument dirname specifies the visited directory,
the argument names lists the files in the directory (gotten from
posix.listdir(dirname)
, so including `.' and
`..'). The visit function may modify names to
influence the set of directories visited below dirname, e.g., to
avoid visiting certain parts of the tree. (The object referred to by
names must be modified in place, using del
or slice
assignment.)
Next: pwd
Prev: posix
Up: UNIX Specific Services
Top: Top