Back to index

python3.2  3.2.2
Functions | Variables
genericpath Namespace Reference

Functions

def exists
def isfile
def isdir
def getsize
def getmtime
def getatime
def getctime
def commonprefix
def _splitext

Variables

list __all__

Detailed Description

Path operations common to more than one OS
Do not use directly.  The OS specific modules import the appropriate
functions from this module themselves.

Function Documentation

def genericpath._splitext (   p,
  sep,
  altsep,
  extsep 
) [private]
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.

Definition at line 85 of file genericpath.py.

00085 
00086 def _splitext(p, sep, altsep, extsep):
00087     """Split the extension from a pathname.
00088 
00089     Extension is everything from the last dot to the end, ignoring
00090     leading dots.  Returns "(root, ext)"; ext may be empty."""
00091     # NOTE: This code must work for text and bytes strings.
00092 
00093     sepIndex = p.rfind(sep)
00094     if altsep:
00095         altsepIndex = p.rfind(altsep)
00096         sepIndex = max(sepIndex, altsepIndex)
00097 
00098     dotIndex = p.rfind(extsep)
00099     if dotIndex > sepIndex:
00100         # skip all leading dots
00101         filenameIndex = sepIndex + 1
00102         while filenameIndex < dotIndex:
00103             if p[filenameIndex:filenameIndex+1] != extsep:
00104                 return p[:dotIndex], p[dotIndex:]
00105             filenameIndex += 1
00106 
00107     return p, p[:0]

Here is the caller graph for this function:

Definition at line 68 of file genericpath.py.

00068 
00069 def commonprefix(m):
00070     "Given a list of pathnames, returns the longest common leading component"
00071     if not m: return ''
00072     s1 = min(m)
00073     s2 = max(m)
00074     for i, c in enumerate(s1):
00075         if c != s2[i]:
00076             return s1[:i]
00077     return s1
00078 
00079 # Split a path in root and extension.
00080 # The extension is everything starting at the last dot in the last
00081 # pathname component; the root is everything before that.
00082 # It is always true that root + ext == p.
00083 
00084 # Generic implementation of splitext, to be parametrized with
# the separators

Here is the call graph for this function:

Here is the caller graph for this function:

def genericpath.exists (   path)
Test whether a path exists.  Returns False for broken symbolic links

Definition at line 15 of file genericpath.py.

00015 
00016 def exists(path):
00017     """Test whether a path exists.  Returns False for broken symbolic links"""
00018     try:
00019         os.stat(path)
00020     except os.error:
00021         return False
00022     return True
00023 
00024 
00025 # This follows symbolic links, so both islink() and isdir() can be true
# for the same path ono systems that support symlinks

Here is the caller graph for this function:

def genericpath.getatime (   filename)
Return the last access time of a file, reported by os.stat().

Definition at line 57 of file genericpath.py.

00057 
00058 def getatime(filename):
00059     """Return the last access time of a file, reported by os.stat()."""
00060     return os.stat(filename).st_atime
00061 

def genericpath.getctime (   filename)
Return the metadata change time of a file, reported by os.stat().

Definition at line 62 of file genericpath.py.

00062 
00063 def getctime(filename):
00064     """Return the metadata change time of a file, reported by os.stat()."""
00065     return os.stat(filename).st_ctime
00066 
00067 
# Return the longest prefix of all list elements.
def genericpath.getmtime (   filename)
Return the last modification time of a file, reported by os.stat().

Definition at line 52 of file genericpath.py.

00052 
00053 def getmtime(filename):
00054     """Return the last modification time of a file, reported by os.stat()."""
00055     return os.stat(filename).st_mtime
00056 

def genericpath.getsize (   filename)
Return the size of a file, reported by os.stat().

Definition at line 47 of file genericpath.py.

00047 
00048 def getsize(filename):
00049     """Return the size of a file, reported by os.stat()."""
00050     return os.stat(filename).st_size
00051 

def genericpath.isdir (   s)
Return true if the pathname refers to an existing directory.

Definition at line 38 of file genericpath.py.

00038 
00039 def isdir(s):
00040     """Return true if the pathname refers to an existing directory."""
00041     try:
00042         st = os.stat(s)
00043     except os.error:
00044         return False
00045     return stat.S_ISDIR(st.st_mode)
00046 

Here is the call graph for this function:

def genericpath.isfile (   path)
Test whether a path is a regular file

Definition at line 26 of file genericpath.py.

00026 
00027 def isfile(path):
00028     """Test whether a path is a regular file"""
00029     try:
00030         st = os.stat(path)
00031     except os.error:
00032         return False
00033     return stat.S_ISREG(st.st_mode)
00034 
00035 
00036 # Is a path a directory?
00037 # This follows symbolic links, so both islink() and isdir()
# can be true for the same path on systems that support symlinks

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
00002            'getsize', 'isdir', 'isfile']

Definition at line 9 of file genericpath.py.