Path operations common to more than one OS
Do not use directly. The OS specific modules import the appropriate
functions from this module themselves.
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile']
# If Python is built without Unicode support, the unicode type
# will not exist. Fake one.
# This is false for dangling symbolic links on systems that support them.
"""Test whether a path exists. Returns False for broken symbolic links"""
# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
"""Test whether a path is a regular file"""
return stat.S_ISREG(st.st_mode)
# This follows symbolic links, so both islink() and isdir()
# can be true for the same path on systems that support symlinks
"""Return true if the pathname refers to an existing directory."""
return stat.S_ISDIR(st.st_mode)
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
"""Return the last modification time of a file, reported by os.stat()."""
return os.stat(filename).st_mtime
"""Return the last access time of a file, reported by os.stat()."""
return os.stat(filename).st_atime
"""Return the metadata change time of a file, reported by os.stat()."""
return os.stat(filename).st_ctime
# Return the longest prefix of all list elements.
"Given a list of pathnames, returns the longest common leading component"
for i, c in enumerate(s1):
# Split a path in root and extension.
# The extension is everything starting at the last dot in the last
# pathname component; the root is everything before that.
# It is always true that root + ext == p.
# Generic implementation of splitext, to be parametrized with
def _splitext(p, sep, altsep, extsep):
"""Split the extension from a pathname.
Extension is everything from the last dot to the end, ignoring
leading dots. Returns "(root, ext)"; ext may be empty."""
altsepIndex = p.rfind(altsep)
sepIndex = max(sepIndex, altsepIndex)
dotIndex = p.rfind(extsep)
filenameIndex = sepIndex + 1
while filenameIndex < dotIndex:
if p[filenameIndex] != extsep:
return p[:dotIndex], p[dotIndex:]