Method (os.path.)
Description
abspath(path)
Generates a full absolute path from a relative path,
i.e. by joining it to the current working directory.
basename(path)
Gives the file or directory name at the end of a path,
removing any leading directories.
commonprefix(list)
Generates the longest string possible which has
characters that matches the start of all the paths in a
list.
dirname(path)
Gives the directory name or names for a path,
removing any file or directory name at the end.
exists(path)
Determines whether a file or directory path exists in
the file system, giving True if it does and False
otherwise. Broken symbolic links give False.
lexists(path)
As above for exists(), but broken symbolic links
give True.
expanduser(path)
Generates a path where any ‘
˜’ or ‘˜user’ stand-ins
for a home directory are expanded to the current
user’s full home directory.
expandvars(path)
Generates a path where any substrings representing
environment variables of the form ‘$env’ or
‘{$env}’ are filled in with the textual value of the
environment variable (if it is known).
getatime(path)
Gets the last access time for a path in seconds,
assuming it exists.
*
getmtime(path)
Get the last modification time for a path in seconds,
assuming it exists.
*
getctime(path)
Gets creation time for a path in seconds, assuming it
exists.
*
getsize(path)
Gets the number of bytes used to store a path,
assuming it exists, on a file system. Generally use to
get the size of a file.
isabs(path)
Determines whether a path is an absolute path (or
otherwise is a relative path). For UNIX-based
systems an absolute path will start from the root ‘/’
and on Windows from ‘' or a drive specification like
‘C:'.
isfile(path)
Determines whether a path represents the location of
a normal file, or a symbolically linked file, i.e. exists
and is not a directory.
isdir(path)
Determines whether a path represents the location of
a directory, or a symbolically linked directory, i.e.
exists and is not a file.
islink(path)
Determines whether a path represents a symbolic
link, whether to a file or directory.
ismount(path)
Determines whether a path represents a location that
points to a different device (hard disk, CD ROM,
USB drive) compared to the parent directory, i.e.
whether it is a mount point.
join(path1, path2, …)
Generates a longer path string by combining
multiple other paths (e.g. sub-directories and a file
name) in order using the appropriate separator for
the system (‘' or ‘/’).
normcase(path)
Generates a path with letters of consistent case; only
has an effect on systems without case sensitivity (in
which case it converts to lower case). Has no effect
on UNIX-like systems.
normpath(path)
Generates a normalised version of a path which has
any redundant directory specifications removed (e.g.
involving ‘../’).
realpath(path)
Provides the real, underlying file-system path for the
destination of a symbolic link. Gives back the input
path unaltered if it is not a symbolic link.
relpath(path, start)
Given a path creates a relative path to that file-
system location from the current working directory,
or optionally from another specified directory.
samefile(path1, path2)
Determines whether two path specifications
represent the same file or directory, giving True if
they do and False otherwise.
sameopenfile(fileObj1,
fileObj2)
Determines whether two file objects represent the
same file or directory, giving True if they do and
False otherwise.
split(path)
Creates a split version of the path, separating any
leading directory from a final file or directory name.
Gives a 2-tuple in the form (leading, final). Same as
(dirname(path),basename(path)).
splitdrive(path)
Creates a split version of the path, separating any
leading drive specification from the rest of a path,
yielding a 2-tuple. Generally only useful on
Windows systems.
splitext(path)
Creates a split version of the path, separating any
trailing file extension (e.g. ‘.jpg’, ‘.py’ etc.) from the
remainder of the path, which generally includes the
directories and the rest of the file name. Gives a 2-
tuple in the form (leading, extension).
Do'stlaringiz bilan baham: |