ostk.core.filesystem.Directory¶
- class Directory¶
Bases:
pybind11_objectMethods
Check if the Directory contains a file with the specified name.
Create the Directory on the filesystem.
Check if the Directory exists on the filesystem.
Get all subdirectories in this Directory.
Get the name of the Directory.
Get the parent directory of this Directory.
Get the full path of the Directory.
Check if the Directory is defined.
Check if the Directory is empty.
Create a Directory from a path.
Remove the Directory from the filesystem.
Get the root directory of the filesystem.
Convert the Directory to a string representation.
Create an undefined Directory.
- contains_file_with_name(
- self: ostk.core.filesystem.Directory,
- name: ostk.core.type.String,
Check if the Directory contains a file with the specified name.
- Parameters:
name (str) -- The name of the file to search for.
- Returns:
True if a file with the given name exists in the directory.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user")) >>> directory.contains_file_with_name("document.txt") # True/False
- create(
- self: ostk.core.filesystem.Directory,
- owner_permissions: ostk.core.filesystem.PermissionSet = PermissionSet.rwx(),
- group_permissions: ostk.core.filesystem.PermissionSet = PermissionSet.rx(),
- other_permissions: ostk.core.filesystem.PermissionSet = PermissionSet.rx(),
- owner_permissions: ostk.core.filesystem.PermissionSet = PermissionSet.rwx(),
Create the Directory on the filesystem.
Creates the directory and any necessary parent directories.
- Parameters:
owner_permissions (PermissionSet, optional) -- Permissions for the owner. Defaults to PermissionSet.rwx().
group_permissions (PermissionSet, optional) -- Permissions for the group. Defaults to PermissionSet.rx().
other_permissions (PermissionSet, optional) -- Permissions for others. Defaults to PermissionSet.rx().
- Raises:
RuntimeError -- If the directory cannot be created.
Example
>>> from ostk.core.filesystem import Path, PermissionSet >>> directory = Directory.path(Path.parse("/tmp/new_directory")) >>> directory.create() # Uses default permissions >>> directory.create(PermissionSet.rwx(), PermissionSet.rx(), PermissionSet.none())
- exists(self: ostk.core.filesystem.Directory) bool¶
Check if the Directory exists on the filesystem.
- Returns:
True if the directory exists, False otherwise.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home")) >>> directory.exists() # True (usually)
- get_directories( ) list[ostk.core.filesystem.Directory]¶
Get all subdirectories in this Directory.
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user")) >>> subdirs = directory.get_directories()
- get_name(self: ostk.core.filesystem.Directory) ostk.core.type.String¶
Get the name of the Directory.
- Returns:
The directory name (last component of the path).
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user/Documents")) >>> directory.get_name() # "Documents"
- get_parent_directory( ) ostk.core.filesystem.Directory¶
Get the parent directory of this Directory.
- Returns:
The parent directory.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user/Documents")) >>> parent = directory.get_parent_directory() >>> parent.get_name() # "user"
- get_path(self: ostk.core.filesystem.Directory) ostk.core.filesystem.Path¶
Get the full path of the Directory.
- Returns:
The complete path to the directory.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user")) >>> path = directory.get_path() >>> str(path) # "/home/user"
- is_defined(self: ostk.core.filesystem.Directory) bool¶
Check if the Directory is defined.
- Returns:
True if the Directory is defined, False otherwise.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user")) >>> directory.is_defined() # True
- is_empty(self: ostk.core.filesystem.Directory) bool¶
Check if the Directory is empty.
- Returns:
True if the directory contains no files or subdirectories, False otherwise.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/tmp")) >>> directory.is_empty() # Depends on contents
- static path(path: ostk.core.filesystem.Path) ostk.core.filesystem.Directory¶
Create a Directory from a path.
- Parameters:
path (Path) -- The path to the directory.
- Returns:
A Directory object representing the specified path.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> path = Path.parse("/home/user") >>> directory = Directory.path(path)
- remove(self: ostk.core.filesystem.Directory) None¶
Remove the Directory from the filesystem.
Removes the directory and all its contents recursively.
- Raises:
RuntimeError -- If the directory cannot be removed.
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/tmp/temp_directory")) >>> directory.remove()
- static root() ostk.core.filesystem.Directory¶
Get the root directory of the filesystem.
- Returns:
The root directory ("/" on Unix systems).
- Return type:
Example
>>> root = Directory.root() >>> root.get_name() # "/"
- to_string(self: ostk.core.filesystem.Directory) ostk.core.type.String¶
Convert the Directory to a string representation.
- Returns:
String representation of the directory path.
- Return type:
Example
>>> from ostk.core.filesystem import Path >>> directory = Directory.path(Path.parse("/home/user")) >>> directory.to_string() # "/home/user"
- static undefined() ostk.core.filesystem.Directory¶
Create an undefined Directory.
- Returns:
An undefined Directory object.
- Return type:
Example
>>> undefined_dir = Directory.undefined() >>> undefined_dir.is_defined() # False