天天看點

os.walk 用法

os.walk(top, topdown=True, οnerrοr=None, followlinks=False)

可以得到一個三元tupple(dirpath, dirnames, filenames),

第一個為起始路徑,第二個為起始路徑下的檔案夾,第三個是起始路徑下的檔案。

dirpath 是一個string,代表目錄的路徑,

dirnames 是一個list,包含了dirpath下所有子目錄的名字。

filenames 是一個list,包含了非目錄檔案的名字。

這些名字不包含路徑資訊,如果需要得到全路徑,需要使用os.path.join(dirpath, name).

原文連結:https://blog.csdn.net/bagboy_taobao_com/article/details/8938126