Low-level File and Directory Manipulation

The os module also contains functions manipulating files and directories

     
     os.access(path,accessmode)     # Checks access permissions on a file
     os.chmod(path,mode)            # Change file permissions
     os.chown(path,uid,gid)         # Change owner and group permissions
     os.link(src,dst)               # Create a hard link
     os.listdir(path)               # Return a list of names in a directory
     os.mkdir(path [,mode])         # Create a directory
     os.remove(path)                # Remove a file
     os.rename(src,dst)             # Rename a file
     os.rmdir(path)                 # Remove a directory
     os.stat(path)                  # Return file information
     os.statvfs(path)               # Return filesystem information
     os.symlink(src,dst)            # Create a symbolic link
     os.unlink(path)                # Remove a file (same as remove)
     os.utime(path,(atime,mtime))   # Change access and modification times

Notes

  • If you care about portability, better to use the os.path module for some of these operations.
  • Note all operations have been listed. Consult a reference.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 41
July 17, 2000, beazley@cs.uchicago.edu
>>>