Python traverses the files under a certain folder

Use the imported library os

import us

Use the function os.listdir() to display the files under the folder in the form of a list

import os

filedir = r"D:\test"
# isdir 判断路径是否为目录
if os.path.isdir(filedir):
    print(os.listdir(filedir))
    for file in os.listdir(filedir):
        print(file)

print result

 

Guess you like

Origin blog.csdn.net/qq_33210042/article/details/131636781