目前使用的python版本是 2.6.6 (不是很新)
直接上code囉.
程式碼如下.
import os
for dirname, dirnames, filenames in os.walk('.'):
# print path to all subdirectories first.
for subdirname in dirnames:
print(os.path.join(dirname, subdirname))
# print path to all filenames.
for filename in filenames:
print(os.path.join(dirname, filename))
資料夾內檔案如下:
執行結果