Posixpath

Posix pathname operations.

Do not import this module directly, import os instead and refer to this module as os.path. (e.g. os.path.exists (p))!

posixpath functions

Function

Result

abspath(path)

Returns absolute path for path, taking current working dir in account.

commonprefix(//st)

Returns the longuest path prefix (taken character-by-character) that is a prefix of all paths in list (or '' if list empty).

dirname/basename (path)

directory and name parts of path. See also split.

exists(path)

True if path is the path of an existing file or directory. See also lexists.

expanduser(path)

Returns a copy of path with "~" expansion done.

expandvars(path)

Returns string that is (a copy of) path with environment vars $name or ${name} expanded. [Windows: case significant; must use Unix: $var notation, not %var%; 2.6: Notation % name% also supported.]

getatime(path)

Returns last access time of path (integer nb of seconds since epoch).

getctime(path)

Returns the metadata change time of path (integer nb of seconds since epoch).

getmtime(path)

Returns last modification time of path (integer nb of seconds since epoch).

getsize(path)

Returns the size in bytes of path. os.error if file inexistent or inaccessible.

isabs(path)

True if path is absolute.

isdir(path)

True if path is a directory.

isfile(path)

True if path is a regular file.

islink(path)

True if path is a symbolic link.

ismount(path)

True if path is a mount point [true for all dirs on Windows].

join(p[,Q[,...]])

Joins one or more path components in a way suitable for the current OS.

lexists(path)

True if the file specified by path exists, whether or not it's a symbolic link (unlike exists).

normcase(path)

Normalizes case of path. Has no effect under Posix.

normpath(path)

Normalizes path, eliminating double slashes, etc...

realpath(path)

Returns the canonical path for path, eliminating any symbolic links encountered in the path.

relpath(path[, start])

Returns a relative filepath to path, from the current directory by default, or from start if specified.

samefile(/\2, f2)

True if the 2 paths f1 and f2 reference the same file.

sameopenfile(fi, f2)

True if the 2 open file objects f1 and f2 reference the same file.

samestat(si, s2)

True if the 2 stat buffers si and s2 reference the same file.

split(p)

Splits p into (head, tail) where tail is last pathname component and head is everything leading up to that. < = > (dirname(p), basename(p))

splitdrive(p)

Splits path p in a pair ('drive:', tail) [Windows]

splitext(p)

Splits into (root, ext) where last comp of root contains no periods and ext is empty or starts with a period. 2.6: Do not split on leading period.

walk(p, v/s/t, arg)

Calls the function visit with arguments (arg, dirname, names) for each directory recursively in the directory tree rooted at p (including p itself if it's a dir). The argument dirname specifies the visited directory, the argument names lists the files in the directory. 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. See also os.walk () for an alternative.

0 0

Responses

  • dieter
    How to use posixpath in python?
    6 years ago

Post a comment