マンガでわかるPython

Xにポスト X@ruten 開発支援 開発/執筆依頼
公開:2025-06-13、更新:2025-06-13

10-8「ファイル一覧」 3ページ

この連載を電子書籍でまとめて読む コンテンツを全て見る

マンガ

3

コンテンツ紹介

この連載を電子書籍でまとめて読む
コンテンツを全て見る

テキスト原稿

# 3p __1__ 猫野: まずは デイレクトリー内の ファイルや ディレクトリーの 一覧を得る方法だ __2__ sys.exec_prefix(Pythonがインストール されているディレクトリー)内を調べる main.py ```py import sys, os p_dir = sys.exec_prefix print(p_dir) files = os.listdir(p_dir) for file in files: p = os.path.join(p_dir, file) if os.path.isfile(p): print(f'[f] {file}') if os.path.isdir(p): print(f'[d] {file}') ``` --- __3__ ディレクトリー内のリスト os.listdir(パス) パスを結合 os.path.join(パス, パス) __4__ パスがファイルか判定 os.path.isfile(パス) パスがディレクトリーか判定 os.path.isdir(パス) --- __5__ 出力 ```python C:\Users\ユーザー名\AppData\Local\Programs\Python\PythonXXX [d] DLLs [d] Doc ︙ [f] LICENSE.txt [f] NEWS.txt ︙ ``` ```c /* 元 C:\Users\yanai\AppData\Local\Programs\Python\Python313 [d] DLLs [d] Doc [d] include [d] Lib [d] libs [f] LICENSE.txt [f] NEWS.txt [f] python.exe [f] python3.dll [f] python312.dll [f] pythonw.exe [d] Scripts [d] tcl [f] vcruntime140.dll [f] vcruntime140_1.dll */ ```

トップページに戻る
Cronus Crown(クロノス・クラウン)のトップページに戻る
(c)2002-2025 Cronus Crown (c)1997-2025 Masakazu Yanai
ご意見・お問い合わせはサイト情報 弊社への連絡までお願いします
個人情報の取り扱い、利用者情報の外部送信について