diff --git a/cpp/src/arrow/filesystem/azurefs.cc b/cpp/src/arrow/filesystem/azurefs.cc index 44bed275ab5d2..a6902fe90ea16 100644 --- a/cpp/src/arrow/filesystem/azurefs.cc +++ b/cpp/src/arrow/filesystem/azurefs.cc @@ -1955,7 +1955,11 @@ class AzureFileSystem::Impl { if (path.Name == base_location.path && !path.IsDirectory) { return NotADir(base_location); } - acc_results->push_back(FileInfoFromPath(base_location.container, path)); + if (internal::GetAbstractPathDepth(path.Name) - + internal::GetAbstractPathDepth(base_location.path) - 1 <= + select.max_recursion) { + acc_results->push_back(FileInfoFromPath(base_location.container, path)); + } } } } catch (const Storage::StorageException& exception) {