マンガでわかるPython

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

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

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

マンガ

7

コンテンツ紹介

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

テキスト原稿

# 7p __1__ 猫野: 最後は ディレクトリー内を 順番に走査していく walk関数だ この方法でも ディレクトリー内の 中身を確かめる ことができる __2__ ```py p_dir = sys.exec_prefix # ディレクトリー内を走査 for root, dirs, files in os.walk(p_dir): # 現在のディレクトリーのパス print(root) # root内のディレクトリー名のリスト print(dirs) # root内のファイル名のリスト print(files) ``` 出力 C:\Users\~\Python\PythonXXX ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'Scripts', 'tcl'] ['LICENSE.txt', 'NEWS.txt', 'python.exe', 'python3.dll', 'python313.dll', 'pythonw.exe', 'vcruntime140.dll', 'vcruntime140_1.dll'] C:\Users\~\Python\PythonXXX\DLLs [] ['libcrypto-3.dll', 'libffi-8.dll', 'libssl-3.dll', 'py.ico', 'pyc.ico', 'pyd.ico', 'pyexpat.pyd', 'python_lib.cat', 'select.pyd', 'sqlite3.dll', 'tcl86t.dll', 'tk86t.dll', 'unicodedata.pyd', 'winsound.pyd', 'zlib1.dll', '_asyncio.pyd', '_bz2.pyd', '_ctypes.pyd', '_ctypes_test.pyd', '_decimal.pyd', '_elementtree.pyd', '_hashlib.pyd', '_lzma.pyd', '_multiprocessing.pyd', '_overlapped.pyd', '_queue.pyd', '_socket.pyd', '_sqlite3.pyd', '_ssl.pyd', '_testbuffer.pyd', '_testcapi.pyd', '_testclinic.pyd', '_testclinic_limited.pyd', '_testconsole.pyd', '_testimportmultiple.pyd', '_testinternalcapi.pyd', '_testlimitedcapi.pyd', '_testmultiphase.pyd', '_testsinglephase.pyd', '_tkinter.pyd', '_uuid.pyd', '_wmi.pyd', '_zoneinfo.pyd'] C:\Users\~\Python\PythonXXX\Doc ['html'] [] ︙ ```c /* C:\Users\yanai\AppData\Local\Programs\Python\Python313 ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'Scripts', 'tcl'] ['LICENSE.txt', 'NEWS.txt', 'python.exe', 'python3.dll', 'python313.dll', 'pythonw.exe', 'vcruntime140.dll', 'vcruntime140_1.dll'] C:\Users\yanai\AppData\Local\Programs\Python\Python313\DLLs [] ['libcrypto-3.dll', 'libffi-8.dll', 'libssl-3.dll', 'py.ico', 'pyc.ico', 'pyd.ico', 'pyexpat.pyd', 'python_lib.cat', 'select.pyd', 'sqlite3.dll', 'tcl86t.dll', 'tk86t.dll', 'unicodedata.pyd', 'winsound.pyd', 'zlib1.dll', '_asyncio.pyd', '_bz2.pyd', '_ctypes.pyd', '_ctypes_test.pyd', '_decimal.pyd', '_elementtree.pyd', '_hashlib.pyd', '_lzma.pyd', '_multiprocessing.pyd', '_overlapped.pyd', '_queue.pyd', '_socket.pyd', '_sqlite3.pyd', '_ssl.pyd', '_testbuffer.pyd', '_testcapi.pyd', '_testclinic.pyd', '_testclinic_limited.pyd', '_testconsole.pyd', '_testimportmultiple.pyd', '_testinternalcapi.pyd', '_testlimitedcapi.pyd', '_testmultiphase.pyd', '_testsinglephase.pyd', '_tkinter.pyd', '_uuid.pyd', '_wmi.pyd', '_zoneinfo.pyd'] C:\Users\yanai\AppData\Local\Programs\Python\Python313\Doc ['html'] [] ︙ */ ```

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