megfile.smart_path module
- class megfile.smart_path.SmartPath(path: str | BasePath | PathLike | int, *other_paths: str | BasePath | PathLike)[source]
Bases:
BasePath
- absolute(*args, **kwargs)
Make the path absolute, without normalization or resolving symlinks. Returns a new path object
- abspath(*args, **kwargs)
Return a normalized absolute version of the path.
- access(*args, **kwargs)
Return True if the path has access permission described by mode.
- property anchor
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- as_posix(*args, **kwargs)
Return a string representation of the path with forward slashes (/)
- as_uri(*args, **kwargs)
- chmod(*args, **kwargs)
- cwd(*args, **kwargs)
Return current working directory
returns: Current working directory
- property drive
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- exists(*args, **kwargs)
Whether the path points to an existing file or directory.
- expanduser(*args, **kwargs)
Return a new path with expanded ~ and ~user constructs, as returned by os.path.expanduser().
Only fs path support this method.
- getmtime(*args, **kwargs)
Return the time of last modification.
- getsize(*args, **kwargs)
Return the size, in bytes.
- glob(*args, **kwargs)
Return files whose paths match the glob pattern.
- glob_stat(*args, **kwargs)
Return an iterator of files with stat whose paths match the glob pattern.
- group(*args, **kwargs)
Return the name of the group owning the file.
- hardlink_to(*args, **kwargs)
Make this path a hard link to the same file as target.
- home(*args, **kwargs)
Return the home directory
returns: Home directory path
- iglob(*args, **kwargs)
Return an iterator of files whose paths match the glob pattern.
- is_absolute(*args, **kwargs)
- is_block_device(*args, **kwargs)
Return True if the path points to a block device (or a symbolic link pointing to a block device), False if it points to another kind of file.
False is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.
- is_char_device(*args, **kwargs)
Return True if the path points to a character device (or a symbolic link pointing to a character device), False if it points to another kind of file.
False is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.
- is_dir(*args, **kwargs)
Return True if the path points to a directory.
- is_fifo(*args, **kwargs)
Return True if the path points to a FIFO (or a symbolic link pointing to a FIFO), False if it points to another kind of file.
False is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.
- is_file(*args, **kwargs)
Return True if the path points to a regular file.
- is_mount(*args, **kwargs)
Test whether a path is a mount point
- Returns:
True if a path is a mount point, else False
- is_relative_to(*args, **kwargs)
- is_reserved(*args, **kwargs)
- is_socket(*args, **kwargs)
Return True if the path points to a Unix socket (or a symbolic link pointing to a Unix socket), False if it points to another kind of file.
False is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated.
- is_symlink(*args, **kwargs)
- iterdir(*args, **kwargs)
Get all contents of given fs path. The result is in ascending alphabetical order.
- Returns:
All contents have in the path in ascending alphabetical order
- joinpath(*args, **kwargs)
Calling this method is equivalent to combining the path with each of the other arguments in turn
- lchmod(*args, **kwargs)
Like chmod() but, if the path points to a symbolic link, the symbolic link’s mode is changed rather than its target’s.
- listdir(*args, **kwargs)
Return the names of the entries in the directory the path points to.
- load(*args, **kwargs)
Read all content in binary.
- lstat(*args, **kwargs)
Like stat() but, if the path points to a symbolic link, return the symbolic link’s information rather than its target’s.
- match(*args, **kwargs)
Match this path against the provided glob-style pattern. Return True if matching is successful, False otherwise
- md5(*args, **kwargs)
- mkdir(*args, **kwargs)
Create a directory.
- property name
A string representing the final path component, excluding the drive and root
- open(*args, **kwargs)
Open the file with mode.
- owner(*args, **kwargs)
Return the name of the user owning the file.
- property parent
The logical parent of the path
- property parents
An immutable sequence providing access to the logical ancestors of the path
- property parts
A tuple giving access to the path’s various components
- property protocol: str
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- read_bytes(*args, **kwargs)
Return the binary contents of the pointed-to file as a bytes object
- read_text(*args, **kwargs)
Return the decoded contents of the pointed-to file as a string
- readlink(*args, **kwargs)
- realpath(*args, **kwargs)
Return the canonical path of the path.
- relative_to(*args, **kwargs)
Compute a version of this path relative to the path represented by other. If it’s impossible, ValueError is raised.
- relpath(start: str | None = None) str [source]
Return the relative path of given path
- Parameters:
start – Given start directory
- Returns:
Relative path from start
- remove(*args, **kwargs)
Remove (delete) the file.
- rename(*args, **kwargs)
rename file
- Parameters:
dst_path – Given destination path
overwrite – whether or not overwrite file when exists
- replace(*args, **kwargs)
move file
- Parameters:
dst_path – Given destination path
overwrite – whether or not overwrite file when exists
- resolve(*args, **kwargs)
Alias of realpath.
- rglob(*args, **kwargs)
This is like calling Path.glob() with “**/” added in front of the given relative pattern
- rmdir(*args, **kwargs)
Remove (delete) the directory.
- property root
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- samefile(*args, **kwargs)
Return whether this path points to the same file
- save(*args, **kwargs)
Write the opened binary stream to the path.
- scan(*args, **kwargs)
Iterate through the files in the directory.
- scan_stat(*args, **kwargs)
Iterate through the files in the directory, with file stat.
- scandir(*args, **kwargs)
Return an iterator of FileEntry objects corresponding to the entries in the directory.
- stat(*args, **kwargs)
Get the status of the path.
- property stem
The final path component, without its suffix
- property suffix
The file extension of the final component
- property suffixes
A list of the path’s file extensions
- symlink(*args, **kwargs)
- symlink_to(*args, **kwargs)
Make this path a symbolic link to target. symlink_to’s arguments is the reverse of symlink’s. Target_is_directory’s value is ignored, only be compatible with pathlib.Path
- touch(*args, **kwargs)
- unlink(*args, **kwargs)
Remove (delete) the file.
- utime(*args, **kwargs)
Sets the access and modified times of the file specified by path to the specified values.
- Parameters:
atime (Union[float, int]) – The access time to be set.
mtime (Union[float, int]) – The modification time to be set.
- Raises:
NotImplementedError – Always raised, since the functionality is unsupported.
- walk(*args, **kwargs)
Generate the file names in a directory tree by walking the tree.
- with_name(*args, **kwargs)
Return a new path with the name changed
- with_stem(*args, **kwargs)
Return a new path with the stem changed
- with_suffix(*args, **kwargs)
Return a new path with the suffix changed
- write_bytes(*args, **kwargs)
Open the file pointed to in bytes mode, write data to it, and close the file
- write_text(*args, **kwargs)
Open the file pointed to in text mode, write data to it, and close the file. The optional parameters have the same meaning as in open().