LoginSignup
0
1

More than 1 year has passed since last update.

【Python】Pythonで特定の拡張子のファイルリストを作る

Last updated at Posted at 2022-06-03

背景

  • pythonでカレントディレクトリから特定の拡張子のファイルリストを作りたい時がある。

目標

  • pythonでカレントディレクトリから特定の拡張子のファイルリストを作る。

コード

特定の拡張子だけのファイルリストの作り方
import os
files = os.listdir(os.getcwd())
md_files = [i for i in files if i.endswith('.md') == True]
特定の拡張子だけのファイルリストの作り方:コメント入り
import os

#カレントのファイルリストを読み込む
files = os.listdir(os.getcwd())

#特定の拡張子のファイルのみを取り出す
#(例として「.md」ファイルを取り出してる)
md_files = [i for i in files if i.endswith('.md') == True]

参考資料

個人ブログ

0
1
3

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
1