Created
February 7, 2017 05:57
-
-
Save devlights/7f2f4c7a46e835ba3c6ceb7f8f78f91f to your computer and use it in GitHub Desktop.
[Python] pathlib の glob と rglob のサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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