summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libppath.tex
blob: c7c2b63c39e7df205ce6e62ab1fdf595ed732123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
\section{Standard Module \sectcode{posixpath}}

\stmodindex{posixpath}
This module implements some useful functions on POSIX pathnames.

\renewcommand{\indexsubitem}{(in module posixpath)}
\begin{funcdesc}{basename}{p}
Return the base name of pathname
\var{p}.
This is the second half of the pair returned by
\code{posixpath.split(\var{p})}.
\end{funcdesc}

\begin{funcdesc}{commonprefix}{list}
Return the longest string that is a prefix of all strings in
\var{list}.
If
\var{list}
is empty, return the empty string (\code{''}).
\end{funcdesc}

\begin{funcdesc}{exists}{p}
Return true if
\var{p}
refers to an existing path.
\end{funcdesc}

\begin{funcdesc}{expanduser}{p}
Return the argument with an initial component of \samp{\~} or
\samp{\~\var{user}} replaced by that \var{user}'s home directory.  An
initial \samp{\~{}} is replaced by the environment variable \code{\${}HOME};
an initial \samp{\~\var{user}} is looked up in the password directory through
the built-in module \code{pwd}.  If the expansion fails, or if the
path does not begin with a tilde, the path is returned unchanged.
\end{funcdesc}

\begin{funcdesc}{expandvars}{p}
Return the argument with environment variables expanded.  Substrings
of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are
replaced by the value of environment variable \var{name}.  Malformed
variable names and references to non-existing variables are left
unchanged.
\end{funcdesc}

\begin{funcdesc}{isabs}{p}
Return true if \var{p} is an absolute pathname (begins with a slash).
\end{funcdesc}

\begin{funcdesc}{isfile}{p}
Return true if \var{p} is an existing regular file.  This follows
symbolic links, so both \code{islink()} and \code{isfile()} can be true for the same
path.
\end{funcdesc}

\begin{funcdesc}{isdir}{p}
Return true if \var{p} is an existing directory.  This follows
symbolic links, so both \code{islink()} and \code{isdir()} can be true for the same
path.
\end{funcdesc}

\begin{funcdesc}{islink}{p}
Return true if
\var{p}
refers to a directory entry that is a symbolic link.
Always false if symbolic links are not supported.
\end{funcdesc}

\begin{funcdesc}{ismount}{p}
Return true if \var{p} is a mount point.  (This currently checks whether
\code{\var{p}/..} is on a different device from \var{p} or whether
\code{\var{p}/..} and \var{p} point to the same i-node on the same
device --- is this test correct for all \UNIX{} and POSIX variants?)
\end{funcdesc}

\begin{funcdesc}{join}{p\, q}
Join the paths
\var{p}
and
\var{q} intelligently:
If
\var{q}
is an absolute path, the return value is
\var{q}.
Otherwise, the concatenation of
\var{p}
and
\var{q}
is returned, with a slash (\code{'/'}) inserted unless
\var{p}
is empty or ends in a slash.
\end{funcdesc}

\begin{funcdesc}{normcase}{p}
Normalize the case of a pathname.  This returns the path unchanged;
however, a similar function in \code{macpath} converts upper case to
lower case.
\end{funcdesc}

\begin{funcdesc}{samefile}{p\, q}
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.
\end{funcdesc}

\begin{funcdesc}{split}{p}
Split the pathname \var{p} in a pair \code{(\var{head}, \var{tail})}, where
\var{tail} is the last pathname component and \var{head} is
everything leading up to that.  If \var{p} ends in a slash (except if
it is the root), the trailing slash is removed and the operation
applied to the result; otherwise, \code{join(\var{head}, \var{tail})} equals
\var{p}.  The \var{tail} part never contains a slash.  Some boundary
cases:\ if \var{p} is the root, \var{head} equals \var{p} and
\var{tail} is empty; if \var{p} is empty, both \var{head} and
\var{tail} are empty; if \var{p} contains no slash, \var{head} is
empty and \var{tail} equals \var{p}.
\end{funcdesc}

\begin{funcdesc}{splitext}{p}
Split the pathname \var{p} in a pair \code{(\var{root}, \var{ext})}
such that \code{\var{root} + \var{ext} == \var{p}},
the last component of \var{root} contains no periods,
and \var{ext} is empty or begins with a period.
\end{funcdesc}

\begin{funcdesc}{walk}{p\, visit\, arg}
Calls the function \var{visit} with arguments
\code{(\var{arg}, \var{dirname}, \var{names})} for each directory in the
directory tree rooted at \var{p} (including \var{p} itself, if it is a
directory).  The argument \var{dirname} specifies the visited directory,
the argument \var{names} lists the files in the directory (gotten from
\code{posix.listdir(\var{dirname})}).  The \var{visit} function may
modify \var{names} to influence the set of directories visited below
\var{dirname}, e.g., to avoid visiting certain parts of the tree.  (The
object referred to by \var{names} must be modified in place, using
\code{del} or slice assignment.)
\end{funcdesc}