公開: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']
[]
︙
*/
```