0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Pythonで「条件に一致するファイルやディレクトリの一覧を取得する(pathlibモジュール)」の動作を確認してみた

Posted at

概要

Pythonで「条件に一致するファイルやディレクトリの一覧を取得する(pathlibモジュール)」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
import pathlib

p = pathlib.Path('./test')
for name in p.glob('**/*.txt'):
  print(name)

以下のコマンドを実行しました。

$ mkdir test
$ touch test/book.png
$ touch test/book.txt
$ touch test/cup.png
$ touch test/cup.txt
$ touch test/pen.png
$ touch test/pen.txt
$ mkdir test/back
$ touch test/back/2018.txt
$ touch test/back/2019.txt
$ touch test/back/2020.txt
$ mkdir test/back/old
$ touch test/back/old/2017.txt
$ mkdir test/img
$ touch test/img/profile.png
$ touch test/img/room.png
$ python3 sample.py 
test/pen.txt
test/book.txt
test/cup.txt
test/back/2020.txt
test/back/2019.txt
test/back/2018.txt
test/back/old/2017.txt

まとめ

何かの役に立てばと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?