Skip to content

Commit

Permalink
Add exists_ok
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya-mohammadi committed Apr 12, 2024
1 parent 7ac92f2 commit f16d99e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deep_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utils.lib_utils.integeration_utils import import_lazy_module

# Deep Utils version number
__version__ = "1.3.28"
__version__ = "1.3.29"

from .utils.constants import DUMMY_PATH, Backends

Expand Down
8 changes: 8 additions & 0 deletions deep_utils/utils/dir_utils/dir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ def list_dir_full_path(directory: str, filter_directories: bool = True,
only_directories: bool = False,
get_full_path: bool = True,
sort: bool = True,
not_exists_is_ok: bool = False,
) -> List[str]:
"""
Returns the full path objects in a directory
Expand All @@ -601,13 +602,20 @@ def list_dir_full_path(directory: str, filter_directories: bool = True,
:param only_directories: If set to True, only directories are extracted and filter_directories is ignored.
:param get_full_path: If set to False, only the name is returned
:param sort: If set to True, the directory will be sorted first!
:param not_exists_is_ok: If set the True, and directory does not exist just returns an empty list,
otherwise raises error.
:return:
"""
interest_extensions = interest_extensions or []
interest_extensions = [interest_extensions] if isinstance(interest_extensions, str) else interest_extensions
interest_extensions = [f".{ext}" if not ext.startswith(".") else ext for ext in
interest_extensions]
output = []
if not os.path.exists(directory):
if not_exists_is_ok:
return output
else:
raise ValueError(f"Directory: {directory} does not exist!")
for filename in sorted(os.listdir(directory)) if sort else os.listdir(directory):
file_path = join(directory, filename)
if not only_directories:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

VERSION = "1.3.28"
VERSION = "1.3.29"

long_description = open("Readme.md", mode="r", encoding="utf-8").read()

Expand Down

0 comments on commit f16d99e

Please sign in to comment.