Lines Matching full:path
1 :mod:`os.path` --- Common pathname manipulations
4 .. module:: os.path
10 .. index:: single: path; operations
16 module. The path parameters can be passed as strings, or bytes, or any object
19 Unlike a Unix shell, Python does not do any *automatic* path expansions.
21 explicitly when an application desires shell-like path expansion. (See also
26 The :mod:`pathlib` module offers high-level path objects.
32 their parameters. The result is an object of the same type, if a path or
37 Since different operating systems have different path name conventions, there
39 :mod:`os.path` module is always the path module suitable for the operating
42 a path that is *always* in one of the different formats. They all have the
57 .. function:: abspath(path)
59 Return a normalized absolutized version of the pathname *path*. On most
61 follows: ``normpath(join(os.getcwd(), path))``.
64 Accepts a :term:`path-like object`.
67 .. function:: basename(path)
69 Return the base name of pathname *path*. This is the second element of the
70 pair returned by passing *path* to the function :func:`split`. Note that
77 Accepts a :term:`path-like object`.
82 Return the longest common sub-path of each pathname in the sequence
86 valid path.
93 Accepts a sequence of :term:`path-like objects <path-like object>`.
98 Return the longest path prefix (taken character-by-character) that is a
105 character at a time. To obtain a valid path, see
110 >>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
113 >>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
117 Accepts a :term:`path-like object`.
120 .. function:: dirname(path)
122 Return the directory name of pathname *path*. This is the first element of
123 the pair returned by passing *path* to the function :func:`split`.
126 Accepts a :term:`path-like object`.
129 .. function:: exists(path)
131 Return ``True`` if *path* refers to an existing path or an open
135 if the *path* physically exists.
138 *path* can now be an integer: ``True`` is returned if it is an
142 Accepts a :term:`path-like object`.
145 .. function:: lexists(path)
147 Return ``True`` if *path* refers to an existing path. Returns ``True`` for
152 Accepts a :term:`path-like object`.
157 .. function:: expanduser(path)
174 If the expansion fails or if the path does not begin with a tilde, the path is
178 Accepts a :term:`path-like object`.
187 .. function:: expandvars(path)
198 Accepts a :term:`path-like object`.
201 .. function:: getatime(path)
203 Return the time of last access of *path*. The return value is a floating point number giving
208 .. function:: getmtime(path)
210 Return the time of last modification of *path*. The return value is a floating point number
215 Accepts a :term:`path-like object`.
218 .. function:: getctime(path)
221 last metadata change, and, on others (like Windows), is the creation time for *path*.
227 Accepts a :term:`path-like object`.
230 .. function:: getsize(path)
232 Return the size, in bytes, of *path*. Raise :exc:`OSError` if the file does
236 Accepts a :term:`path-like object`.
239 .. function:: isabs(path)
241 Return ``True`` if *path* is an absolute pathname. On Unix, that means it
246 Accepts a :term:`path-like object`.
249 .. function:: isfile(path)
251 Return ``True`` if *path* is an :func:`existing <exists>` regular file.
253 be true for the same path.
256 Accepts a :term:`path-like object`.
259 .. function:: isdir(path)
261 Return ``True`` if *path* is an :func:`existing <exists>` directory. This
263 for the same path.
266 Accepts a :term:`path-like object`.
269 .. function:: islink(path)
271 Return ``True`` if *path* refers to an :func:`existing <exists>` directory
276 Accepts a :term:`path-like object`.
279 .. function:: ismount(path)
281 Return ``True`` if pathname *path* is a :dfn:`mount point`: a point in a
283 function checks whether *path*'s parent, :file:`{path}/..`, is on a different
284 device than *path*, or whether :file:`{path}/..` and *path* point to the same
288 always mount points, and for any other path ``GetVolumePathName`` is called
289 to see if it is different from the input path.
295 Accepts a :term:`path-like object`.
298 .. function:: join(path, *paths)
300 Join one or more path segments intelligently. The return value is the
301 concatenation of *path* and all members of *\*paths*, with exactly one
304 ends in a separator. If a segment is an absolute path (which on Windows
306 joining continues from the absolute path segment.
308 On Windows, the drive is not reset when a rooted path segment (e.g.,
310 absolute path, all previous segments are ignored and the drive is reset. Note
312 ``os.path.join("c:", "foo")`` represents a path relative to the current
316 Accepts a :term:`path-like object` for *path* and *paths*.
319 .. function:: normcase(path)
323 On other operating systems, return the path unchanged.
326 Accepts a :term:`path-like object`.
329 .. function:: normpath(path)
333 become ``A/B``. This string manipulation may change the meaning of a path
346 Accepts a :term:`path-like object`.
349 .. function:: realpath(path, *, strict=False)
351 Return the canonical path of the specified filename, eliminating any symbolic
352 links encountered in the path (if they are supported by the operating
355 If a path doesn't exist or a symlink loop is encountered, and *strict* is
356 ``True``, :exc:`OSError` is raised. If *strict* is ``False``, the path is
361 This function emulates the operating system's procedure for making a path
363 to how links and subsequent path components interact.
369 Accepts a :term:`path-like object`.
378 .. function:: relpath(path, start=os.curdir)
380 Return a relative filepath to *path* either from the current directory or
381 from an optional *start* directory. This is a path computation: the
382 filesystem is not accessed to confirm the existence or nature of *path* or
383 *start*. On Windows, :exc:`ValueError` is raised when *path* and *start*
391 Accepts a :term:`path-like object`.
409 Accepts a :term:`path-like object`.
422 Accepts a :term:`path-like object`.
438 Accepts a :term:`path-like object`.
441 .. function:: split(path)
443 Split the pathname *path* into a pair, ``(head, tail)`` where *tail* is the
445 *tail* part will never contain a slash; if *path* ends in a slash, *tail*
446 will be empty. If there is no slash in *path*, *head* will be empty. If
447 *path* is empty, both *head* and *tail* are empty. Trailing slashes are
449 all cases, ``join(head, tail)`` returns a path to the same location as *path*
454 Accepts a :term:`path-like object`.
457 .. function:: splitdrive(path)
459 Split the pathname *path* into a pair ``(drive, tail)`` where *drive* is either
462 + tail`` will be the same as *path*.
464 On Windows, splits a pathname into drive/UNC sharepoint and relative path.
466 If the path contains a drive letter, drive will contain everything
472 If the path contains a UNC path, drive will contain the host name
479 Accepts a :term:`path-like object`.
482 .. function:: splitext(path)
484 Split the pathname *path* into a pair ``(root, ext)`` such that ``root + ext ==
485 path``, and the extension, *ext*, is empty or begins with a period and contains at
488 If the path contains no extension, *ext* will be ``''``::
493 If the path contains an extension, then *ext* will be set to this extension,
501 Leading periods of the last component of the path are considered to
510 Accepts a :term:`path-like object`.