Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cloudpathlib/cloudpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ def _glob(self, selector):
yield self.client.CloudPath(f"{self.cloud_prefix}{self.drive}{p}")

def glob(self, pattern):
if pattern == "*":
yield from (path for path, is_file in self.client._list_dir(self, recursive=False))
return
if pattern == "**/*":
yield from (path for path, is_file in self.client._list_dir(self, recursive=True))
return
self._glob_checks(pattern)

pattern_parts = PurePosixPath(pattern).parts
Expand All @@ -369,6 +375,9 @@ def glob(self, pattern):
yield from self._glob(selector)

def rglob(self, pattern):
if pattern == "*":
yield from (path for path, is_file in self.client._list_dir(self, recursive=True))
return
self._glob_checks(pattern)

pattern_parts = PurePosixPath(pattern).parts
Expand Down
3 changes: 3 additions & 0 deletions tests/test_cloudpath_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def _check_glob(pattern, glob_method):
)

# glob_common
_check_glob("**/*", "glob")
_check_glob("*", "glob")
_check_glob("fileA", "glob")
_check_glob("fileB", "glob")
_check_glob("dir*/file*", "glob")
Expand All @@ -157,6 +159,7 @@ def _check_glob(pattern, glob_method):
_check_glob("*/fileB", "glob")

# rglob_common
_check_glob("*", "rglob")
_check_glob("fileA", "rglob")
_check_glob("fileB", "rglob")
_check_glob("*/fileA", "rglob")
Expand Down