#!/usr/bin/python
import os.path
def readxmls(folder):
#三個引數:分別返回1.父目錄 2.所有資料夾名字(不含路徑) 3.所有檔案名字
for parent,dirnames,filenames in os.walk(folder):
for dirname in dirnames:
print("parent is:" + parent)
print("dirname is" + dirname)
#readxmls(os.path.join(parent, dirname))這句不能有!!!
for filename in filenames:
print("parent is:" + parent)
print("filename is:" + filename)
print("the full name of the file is:" + os.path.join(parent,filename)) #輸出檔案路徑資訊
if __name__ == '__main__':
readxmls('xmlfiles')
------備註-----
os.walk方法本來就是遞迴,除錯了很久也沒搞明白……
python遞迴遍歷資料夾檢查檔案
python遞迴遍歷資料夾檢查缺少debug new的cpp檔案 3x版本的python使用print需要用括號列印字串,如print file name import os check path f some dir debug str define new debug new report lo...
使用遞迴遍歷資料夾
using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...
work Python 遞迴遍歷資料夾
import os def get log path dict log path home logs for root,dirs,files in os.walk log path log path dict dict for dir name in dirs dir path os.path.jo...