shared.file_directory_ops
- shared.file_directory_ops.change_directory(new_directory)[source]
Context manager to change the working directory temporarily.
- shared.file_directory_ops.copy_to(input, output, include_directories=True)[source]
Copies a file to a new location.
- Parameters:
input (str) – The path of the file to be copied.
output (str) – The path to copy the file to.
- shared.file_directory_ops.delete_files_or_directories(*paths, ignore_errors=False)[source]
Deletes the files or directories specified by the given paths.
- Parameters:
paths (str) – The paths of files or directories to be deleted.
- Raises:
FileNotFoundError – If the given path does not exist.
Usage:
delete_files_or_directories('/path/to/file', '/path/to/directory') # Deletes specified file and directory
- shared.file_directory_ops.file_len(file_path)[source]
Returns the number of lines in a file.
- Parameters:
file_path (str) – The path to the file.
- Returns:
The number of lines in the file.
- Return type:
int
- shared.file_directory_ops.file_lenth(filename)[source]
Returns the number of lines in a file.
- Parameters:
filename (str) – The path to the file.
- Returns:
The number of lines in the file.
- Return type:
int
- shared.file_directory_ops.find(filename, *args)[source]
Searches for a file in multiple directories.
- Parameters:
filename (str) – The name of the file to search for.
args (str) – The directories to search in.
- Returns:
The first directory where the file was found.
- Return type:
str
- shared.file_directory_ops.get_all_files_in_directory(directory)[source]
Returns all files in a directory.
- Parameters:
directory (str) – The path to the directory.
- Returns:
All files in the directory.
- Return type:
list
- shared.file_directory_ops.get_folders_in_directory(directory)[source]
Returns the folders in a directory.
- Parameters:
directory (str) – The path to the directory.
- Returns:
The folders in the directory.
- Return type:
list
- shared.file_directory_ops.make_directory(output_dir: str, delete_if_exists: bool = False)[source]
Creates a directory at the specified path. If the directory already exists and ‘delete_if_exists’ is True, it deletes the existing directory before creating a new one.
- Parameters:
output_dir (str) – The path where the directory is to be created.
delete_if_exists (bool) – If True, deletes the directory at ‘output_dir’ if it exists. Default is False.
Usage:
make_directory('/path/to/directory', delete_if_exists=True) # Creates directory, deleting existing one if necessary
- shared.file_directory_ops.uniquify(filepath)[source]
Makes a file path unique by appending a counter to the file name.
- Parameters:
filepath (str) – The initial file path.
- Returns:
A unique file path.
- Return type:
str
