6.1.4 Files and Directories

access (path, mode)
Check read/write/execute permissions for this process or extance of file path. Return 1 if access is granted, 0 if not. See the Unix manual for the semantics. Availability: Unix.

chmod (path, mode)
Change the mode of path to the numeric mode. Availability: Unix, Windows.

chown (path, uid, gid)
Change the owner and group id of path to the numeric uid and gid. Availability: Unix.

link (src, dst)
Create a hard link pointing to src named dst. Availability: Unix.

listdir (path)
Return a list containing the names of the entries in the directory. The list is in arbitrary order. It does not include the special entries '.' and '..' even if they are present in the directory. Availability: Macintosh, Unix, Windows.

lstat (path)
Like stat(), but do not follow symbolic links. Availability: Unix.

mkfifo (path[, mode])
Create a FIFO (a named pipe) named path with numeric mode mode. The default mode is 0666 (octal). The current umask value is first masked out from the mode. Availability: Unix.

FIFOs are pipes that can be accessed like regular files. FIFOs exist until they are deleted (for example with os.unlink()). Generally, FIFOs are used as rendezvous between ``client'' and ``server'' type processes: the server opens the FIFO for reading, and the client opens it for writing. Note that mkfifo() doesn't open the FIFO -- it just creates the rendezvous point.

mkdir (path[, mode])
Create a directory named path with numeric mode mode. The default mode is 0777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out. Availability: Macintosh, Unix, Windows.

makedirs (path[, mode])
Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. Throws an error exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal). New in version 1.5.2.

readlink (path)
Return a string representing the path to which the symbolic link points. Availability: Unix.

remove (path)
Remove the file path. See rmdir() below to remove a directory. This is identical to the unlink() function documented below. Availability: Macintosh, Unix, Windows.

removedirs (path)
Recursive directory removal function. Works like rmdir() except that, if the leaf directory is successfully removed, directories corresponding to rightmost path segments will be pruned way until either the whole path is consumed or an error is raised (which is ignored, because it generally means that a parent directory is not empty). Throws an error exception if the leaf directory could not be successfully removed. New in version 1.5.2.

rename (src, dst)
Rename the file or directory src to dst. Availability: Macintosh, Unix, Windows.

renames (old, new)
Recursive directory or file renaming function. Works like rename(), except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path segments of the old name will be pruned away using removedirs().

Note: this function can fail with the new directory structure made if you lack permissions needed to remove the leaf directory or file. New in version 1.5.2.

rmdir (path)
Remove the directory path. Availability: Macintosh, Unix, Windows.

stat (path)
Perform a stat() system call on the given path. The return value is a tuple of at least 10 integers giving the most important (and portable) members of the stat structure, in the order st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime. More items may be added at the end by some implementations. (On MS Windows, some items are filled with dummy values.) Availability: Macintosh, Unix, Windows.

Note: The standard module stat defines functions and constants that are useful for extracting information from a stat structure.

statvfs (path)
Perform a statvfs() system call on the given path. The return value is a tuple of 10 integers giving the most common members of the statvfs structure, in the order f_bsize, f_frsize, f_blocks, f_bfree, f_bavail, f_files, f_ffree, f_favail, f_flag, f_namemax. Availability: Unix.

Note: The standard module statvfs defines constants that are useful for extracting information from a statvfs structure.

symlink (src, dst)
Create a symbolic link pointing to src named dst. Availability: Unix.

unlink (path)
Remove the file path. This is the same function as remove(); the unlink() name is its traditional Unix name. Availability: Macintosh, Unix, Windows.

utime (path, (atime, mtime))
Set the access and modified time of the file to the given values. (The second argument is a tuple of two items.) Availability: Macintosh, Unix, Windows.


Send comments on this document to python-docs@python.org.


Banner.Novgorod.Ru