zoukankan      html  css  js  c++  java
  • python3 遍历文件

    程序很简单,parent,dirnames,filenames分别表明当前目录下的文件夹数及文件数,然后通过os.wolk向深入遍历。

     

    import os
    import os.path

    # this folder is custom
    rootdir="G:Download"
    for parent,dirnames,filenames in os.walk(rootdir):
        #case 1:
        for dirname in dirnames:
            print("parent folder is:" + parent)
            print("dirname is:" + dirname)
        #case 2
        for filename in filenames:   
            print("parent folder is:" + parent)
            print("filename with full path:"+ os.path.join(parent,filename))

  • 相关阅读:
    Fire
    Apple Tree
    访问艺术馆
    三角关系
    字母表
    折纸
    旅行
    单词分类

    圆桌游戏
  • 原文地址:https://www.cnblogs.com/luhouxiang/p/4886659.html
Copyright © 2011-2022 走看看