Skip to content

Instantly share code, notes, and snippets.

@horvatha
Last active April 18, 2024 14:19
Show Gist options
  • Save horvatha/4cb628d8201e569df689e08e50649e7d to your computer and use it in GitHub Desktop.
Save horvatha/4cb628d8201e569df689e08e50649e7d to your computer and use it in GitHub Desktop.
import fnmatch
import os
import sys
from pathlib import Path
eleresi_ut = Path.home() / "Documents"
minta = 'Co*t*.*'
# good old walk
for root, dirs, files in os.walk(eleresi_ut):
for filename in fnmatch.filter(files, minta):
print(root + filename)
# pathlib's walk
major, minor = sys.version_info[:2]
if (major, minor) >= (3, 12):
print("Yeah. Once again.")
for root, dirs, files in eleresi_ut.walk():
for filename in fnmatch.filter(files, minta):
print(root / filename)
else:
print("Second version needs Python 3.12+")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment