0
0

More than 3 years have passed since last update.

pythonのファイルを扱うpathlibというライブラリ

Last updated at Posted at 2021-04-11

pathlibでファイル操作を自動化したい。
そのために、まずpathをいくつか使用して慣れてみたい。

F1) Path.glob
現在プログラムフォルダ内に存在するファイルを取得する

例:
from pathlib import Path
current = Path()
for Path in current.glob(('*.jpg')):
print(Path)

結果:jpgの拡張子のファイルを取得する

F2) サブフォルダ内のファイルも対象にする
**/をつけることで、サブフォルダ内も取得可能。

例:
from pathlib import Path
current = Path()
for path in current.glob('*/.jpg'):
print(path)

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