PyDocs

Nav

File and Directory Access

Path

pathlib

class (source)
  • Path(*pathsegments)
PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers
methods to do system calls on path objects. Depending on your system,
instantiating a Path will return either a PosixPath or a WindowsPath
object. You can also instantiate a PosixPath or WindowsPath directly,
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
Members of Path

a

absolute
Return an absolute version of this path No normalization or symlink resolution is performed.
as_uri
Return the path as a URI.

c

chmod
Change the permissions of the path, like os.chmod().
copy
Recursively copy this file or directory tree to the given destination.
copy_into
Copy this file or directory tree into the given existing directory.
cwd
Return a new path pointing to the current working directory.

e

exists
Whether this path exists.
expanduser
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)

f

from_uri
Return a new path from the given 'file' URI.

g

glob
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
group
Return the group name of the file gid.

h

hardlink_to
Make this path a hard link pointing to the same file as *target*.
home
Return a new path pointing to expanduser('~').

i

info
A PathInfo object that exposes the file type and other file attributes of this path.
is_block_device
Whether this path is a block device.
is_char_device
Whether this path is a character device.
is_dir
Whether this path is a directory.
is_fifo
Whether this path is a FIFO.
is_file
Whether this path is a regular file (also True for symlinks pointing to regular files).
is_junction
Whether this path is a junction.
is_mount
Check if this path is a mount point
is_socket
Whether this path is a socket.
is_symlink
Whether this path is a symbolic link.
iterdir
Yield path objects of the directory contents.

l

lchmod
Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's.
lstat
Like stat(), except if the path points to a symlink, the symlink's status information is returned, rather than its target's.

m

mkdir
Create a new directory at this given path.
move
Recursively move this file or directory tree to the given destination.
move_into
Move this file or directory tree into the given existing directory.

o

open
Open the file pointed to by this path and return a file object, as the built-in open() function does.
owner
Return the login name of the file owner.

r

read_bytes
Open the file in bytes mode, read it, and close the file.
read_text
Open the file in text mode, read it, and close the file.
readlink
Return the path to which the symbolic link points.
rename
Rename this path to the target path.
replace
Rename this path to the target path, overwriting if that path exists.
resolve
Make the path absolute, resolving all symlinks on the way and also normalizing it.
rglob
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
rmdir
Remove this directory.

s

samefile
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
stat
Return the result of the stat() system call on this path, like os.stat() does.
symlink_to
Make this path a symlink pointing to the target path.

t

touch
Create this file with the given access mode, if it doesn't exist.

u

unlink
Remove this file or link.

w

walk
Walk the directory tree from this directory, similar to os.walk().
write_bytes
Open the file in bytes mode, write to it, and close the file.
write_text
Open the file in text mode, write to it, and close the file.
1 Example
>>> Path('setup.py')
PosixPath('setup.py')
from the Python docs
See Also
No see-alsos for pathlib/Path
0 Notes
No notes for Path