Skip to content

Instantly share code, notes, and snippets.

@devlights
Created February 7, 2017 05:57
Show Gist options
  • Select an option

  • Save devlights/7f2f4c7a46e835ba3c6ceb7f8f78f91f to your computer and use it in GitHub Desktop.

Select an option

Save devlights/7f2f4c7a46e835ba3c6ceb7f8f78f91f to your computer and use it in GitHub Desktop.
[Python] pathlib の glob と rglob のサンプル
# coding: utf-8
import pathlib
from pprint import pprint as pp
file_path = r'/Users/xxxxx/anaconda'
p = pathlib.Path(file_path)
if not p.exists():
print('存在しない')
else:
pattern = '**/anaconda*.pyc'
file_list = [x.name for x in p.glob(pattern)]
pp(file_list)
print('------------------------------')
print(f'count={len(file_list)}')
pattern = 'anaconda*.pyc'
file_list = [x.name for x in p.rglob(pattern)] # rglob は recursive glob の意味
pp(file_list)
print('------------------------------')
print(f'count={len(file_list)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment