Reference¶
dsg_lib.common_functions.folder_functions
¶
This module contains functions for working with directories and files.
Functions:
Name | Description |
---|---|
last_data_files_changed |
Get the last modified file in a |
get_directory_list |
Get a list of directories in the |
specified directory. make_folder |
Make a folder in a |
specific directory. remove_folder |
Remove a folder from the |
Example:
from dsg_lib.common_functions import folder_functions
# Get the last modified file in a directory time_stamp, file_path =
folder_functions.last_data_files_changed("/path/to/directory") # Returns:
(datetime.datetime(2022, 1, 1, 12, 0, 0), '/path/to/directory/test.txt')
# Get a list of directories in the specified directory directories =
folder_functions.get_directory_list("/path/to/directory") # Returns:
['/path/to/directory/dir1', '/path/to/directory/dir2']
# Make a folder in a specific directory
folder_functions.make_folder("/path/to/directory/new_folder") # Creates a new
folder at '/path/to/directory/new_folder'
# Remove a folder from the specified directory
folder_functions.remove_folder("/path/to/directory/old_folder") # Removes the
folder at '/path/to/directory/old_folder'
Author: Mike Ryan Date: 2024/05/16 License: MIT
get_directory_list(file_directory)
¶
Get a list of directories in the specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_directory
|
str
|
The path of the directory to check. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of directories in the specified directory. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the directory does not exist. |
Example:
from dsg_lib import file_functions
directories = file_functions.get_directory_list("/path/to/directory")
# Returns: ['/path/to/directory/dir1', '/path/to/directory/dir2']
Source code in dsg_lib/common_functions/folder_functions.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
last_data_files_changed(directory_path)
¶
Get the last modified file in a directory and return its modification time and path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory_path
|
str
|
The path of the directory to check. |
required |
Returns:
Type | Description |
---|---|
datetime
|
Tuple[datetime, str]: A tuple containing the modification time and path |
str
|
of the last modified file. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the directory does not exist. |
Example:
from dsg_lib import file_functions
time_stamp, file_path = file_functions.last_data_files_changed("/path/to/directory")
# Returns: (datetime.datetime(2022, 1, 1, 12, 0, 0), '/path/to/directory/test.txt')
Source code in dsg_lib/common_functions/folder_functions.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
remove_folder(file_directory)
¶
Remove a folder from the specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_directory
|
str
|
The directory containing the folder to be removed. |
required |
Returns:
Type | Description |
---|---|
None
|
None. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified directory does not exist. OSError: |
Example:
from dsg_lib.common_functions import file_functions
file_functions.remove_folder("/path/to/directory/old_folder")
# Removes the folder at '/path/to/directory/old_folder'
Source code in dsg_lib/common_functions/folder_functions.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|