File Tests

os.path - Functions for portable filename inquires

     exists(path)           # Test for existence
     isabs(path)            # Return 1 if path is an absolute pathname
     isfile(path)           # Return 1 if path is a regular file
     isdir(path)            # Return 1 if path is a directory
     islink(path)           # Return 1 if path is a symlink
     ismount(path)          # Return 1 if path is a mountpoint
     getatime(path)         # Get access time
     getmtime(path)         # Get modification time
     getsize(path)          # Get file size in bytes
     samefile(path1,path2)  # Return 1 if path1 and path2 are the same file
     sameopenfile(f1,f2)    # Return 1 if file objects f1 and f2 are same file.

Notes:

  • samefile() and sameopenfile() useful if file referenced by symbolic links or aliases.
  • The stat module provides lower-level functions for file inquiry.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 37
July 17, 2000, beazley@cs.uchicago.edu
>>>