Skip to content
Open
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Unreleased
----------
- .
- Added the `maxdepth` parameter to `find()` (#435)

2026.5.0
--------
Expand Down
13 changes: 12 additions & 1 deletion adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ async def _details(

return output

async def _find(self, path, withdirs=False, prefix="", **kwargs):
async def _find(self, path, withdirs=False, prefix="", maxdepth=None, **kwargs):
"""List all files below path.
Like posix ``find`` command without conditions.

Expand All @@ -976,6 +976,8 @@ async def _find(self, path, withdirs=False, prefix="", **kwargs):
when used by glob, but users usually only want files.
prefix: str
Only return files that match `^{path}/{prefix}`
maxdepth: int or None
Maximum depth to recurse.
kwargs are passed to ``ls``.
"""
full_path = self._strip_protocol(path)
Expand Down Expand Up @@ -1037,6 +1039,15 @@ async def _find(self, path, withdirs=False, prefix="", **kwargs):
if withdirs:
files.update(dirs)
files = {k: v for k, v in files.items() if k.startswith(target_path)}

if maxdepth is not None:
base_depth = full_path.rstrip("/").count("/")
files = {
k: v
for k, v in files.items()
if k.rstrip("/").count("/") <= base_depth + maxdepth
}

names = sorted([n for n in files.keys()])
if not detail:
return names
Expand Down
23 changes: 23 additions & 0 deletions adlfs/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2610,3 +2610,26 @@ def test_etag_normalized_form(storage):
)
def test_striping_etag(input_etag, expected_etag):
assert _normalize_etag_quotes(input_etag) == expected_etag


def test_find_maxdepth(storage):
fs = AzureBlobFileSystem(
account_name=storage.account_name,
connection_string=CONN_STR,
)

assert fs.find("data/root", maxdepth=1) == ["data/root/rfile.txt"]

assert fs.find("data/root", maxdepth=1, withdirs=True) == [
"data/root/a",
"data/root/a1",
"data/root/b",
"data/root/c",
"data/root/d",
"data/root/e+f",
"data/root/rfile.txt",
]

assert fs.find("data/root", maxdepth=2) == fs.find("data/root")

assert fs.find("data/root", maxdepth=None) == fs.find("data/root")
Loading