📜  python 循环遍历目录中的文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:49.324000             🧑  作者: Mango

代码示例5
basepath = "pathtodir/DataFiles/"
for filename in os.listdir(basepath):
    if filename.endswith(".log"): 
        print(os.path.join("./DataFiles", filename))

        with open(basepath + filename) as openfile:    
            for line in openfile:
            ........