walking along and processing files in directory in python

前端 未结 3 822
时光说笑
时光说笑 2021-01-07 01:27

I have huge data in a directory tree format like:
c:/user/name/class/std/section I to VI [all section has individual folder i.e. 6 folder in total and all folder h

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 02:16

    you can try this code :

    import os
    folder = 'C:'
    
    for root, dirs, files in os.walk(folder):
        for name in files:
            print os.path.join(root, name)
        for name in dirs:
            print os.path.join(root, name)
    

    UPDATE:

    import os folder = 'C:'

    for root, dirs, files in os.walk(folder):
        for name in files:
            nm, ext = os.path.splitext(name)
            if ext == ".csv":
                print os.path.join(root, name)
    

提交回复
热议问题