Skip to content

Instantly share code, notes, and snippets.

@svfat
Created June 16, 2025 16:27
Show Gist options
  • Save svfat/ec0d06e8c51ceb4256290fa9e6383546 to your computer and use it in GitHub Desktop.
Save svfat/ec0d06e8c51ceb4256290fa9e6383546 to your computer and use it in GitHub Desktop.
test task
import argparse
from pathlib import Path
def recursive_search(item: Path, name_part: str) -> list[Path]:
matches = []
if item.is_dir():
for sub_item in item.iterdir():
matches += recursive_search(
sub_item,
name_part
)
elif item.is_file() and name_part in item.name:
matches.append(item)
return matches
def main(start_dir: str, name_part: str) -> None:
matches = recursive_search(Path(start_dir), name_part)
for match in matches:
print(match)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'start_dir'
)
parser.add_argument(
'name_part'
)
args = parser.parse_args()
main(
start_dir=args.start_dir,
name_part=args.name_part
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment