Skip to content

Commit 3aa6b4c

Browse files
committed
fix glob, add globtest example
1 parent ebba93e commit 3aa6b4c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

adafruit_pathlib.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,16 @@ def is_file(self):
166166

167167
@staticmethod
168168
def _get_mount_for(path):
169-
path = path.rstrip("/")
169+
if len(path) > 1:
170+
path = path.rstrip("/")
171+
170172
if path[0] != "/":
171173
path = os.getcwd() + "/" + path
172174
while len(path) > 0:
173175
try:
174176
return storage.getmount(path)
175177
except OSError:
176-
pos = path.rfind("/")
178+
pos = path.rfind("/") + 1
177179
path = path[:pos]
178180
return None
179181

@@ -186,7 +188,7 @@ def _glob(self, path, pattern, recursive):
186188
raise NotImplementedError("? single wildcards not implemented.")
187189

188190
if n_wildcards == 0:
189-
raise ValueError
191+
raise ValueError("Must have exactly one wildcard")
190192
elif n_wildcards > 1:
191193
raise NotImplementedError("Multiple * wildcards not implemented.")
192194

@@ -349,9 +351,7 @@ def iterdir(self):
349351
"""
350352
if not self.is_dir():
351353
raise OSError(errno.ENOTDIR, f"Not a directory: {self._path}")
352-
print(f"self._path: {self._path}")
353354
for name in os.listdir(self._path):
354-
print(f"name: {name}")
355355
yield Path(self._path, name)
356356

357357
def __hash__(self):

examples/pathlib_globtest.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Tim Cocks for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
from adafruit_pathlib import Path
5+
6+
p = Path("/lib")
7+
8+
for file in p.glob("adafruit_*"):
9+
print(file)

0 commit comments

Comments
 (0)