📜  如何遍历目录中的文件python代码示例

📅  最后修改于: 2022-03-11 14:45:53.705000             🧑  作者: 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:
            ........