Next / Previous / Contents / Shipman's homepage

6.13. PathInfo.__fileType(): Get the file type code

This method derives the one-letter file type code: - for a regular file, d for a directory, or l for a link. Because it is a private method of the class, its name starts with two underscores (__) so it is not visible to code that imports this class.

pathinfo.py
# - - -   P a t h I n f o . _ _ f i l e T y p e   - - -

    def __fileType ( self ):
        """Return the file type code.

          [ if self is a regular file ->
              return "-"
            if self is a directory ->
              return "d"
            if self is a soft link ->
              return "l" ]
        """

Just as a defensive programming measure, we return "?" if for some reason the path is neither a file, a directory, or a soft link. This can happen for Unix device files, but those are beyond the intended audience of the pathinfo.py module.

pathinfo.py
        if self.isLink():
            return "l"
        elif self.isDir():
            return "d"
        elif self.isFile():
            return "-"
        else:
            return "?"