Find files matching pattern. Args: directory: Directory to search pattern: File pattern (supports wildcards) recursive: Search recursively Returns: List of matching file paths
(directory: str, pattern: str, recursive: bool = True)
| 218 | |
| 219 | @staticmethod |
| 220 | def find_files(directory: str, pattern: str, recursive: bool = True) -> List[str]: |
| 221 | """ |
| 222 | Find files matching pattern. |
| 223 | |
| 224 | Args: |
| 225 | directory: Directory to search |
| 226 | pattern: File pattern (supports wildcards) |
| 227 | recursive: Search recursively |
| 228 | |
| 229 | Returns: |
| 230 | List of matching file paths |
| 231 | """ |
| 232 | import fnmatch |
| 233 | |
| 234 | matches = [] |
| 235 | |
| 236 | if recursive: |
| 237 | for root, dirnames, filenames in os.walk(directory): |
| 238 | for filename in filenames: |
| 239 | if fnmatch.fnmatch(filename, pattern): |
| 240 | matches.append(os.path.join(root, filename)) |
| 241 | else: |
| 242 | try: |
| 243 | filenames = os.listdir(directory) |
| 244 | for filename in filenames: |
| 245 | if fnmatch.fnmatch(filename, pattern): |
| 246 | filepath = os.path.join(directory, filename) |
| 247 | if os.path.isfile(filepath): |
| 248 | matches.append(filepath) |
| 249 | except OSError: |
| 250 | pass |
| 251 | |
| 252 | return sorted(matches) |
| 253 | |
| 254 | |
| 255 | class VersionUtils: |