Testing files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iLL
    New Member
    • Oct 2006
    • 63

    #1

    Testing files

    Is there anyway to check if an argument is a file or directory?


    Like `test -d .` in bash
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by iLL
    Is there anyway to check if an argument is a file or directory?

    Like `test -d .` in bash
    In the os package, in the path module, these functions appear:

    isabs( path)
    Return True if path is an absolute pathname (begins with a slash).

    isfile( path)
    Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

    isdir( path)
    Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.

    for example:

    >>> from os.path import *
    >>> isdir(r"C:\Prog ram Files")
    True
    >>>

    Comment

    • iLL
      New Member
      • Oct 2006
      • 63

      #3
      Originally posted by bartonc
      In the os package, in the path module, these functions appear:

      isabs( path)
      Return True if path is an absolute pathname (begins with a slash).

      isfile( path)
      Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

      isdir( path)
      Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.

      for example:

      >>> from os.path import *
      >>> isdir(r"C:\Prog ram Files")
      True
      >>>

      Thank you!

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by iLL
        Thank you!
        You're welcome! Keep posting,
        Barton

        Comment

        Working...