python遍历文件夹内文件的两种方法

方法一:

import os

filePath = r'C:\Users\Administrator\Desktop\hunman'
for i, j, k in os.walk(filePath):
    # print(k)
    for file in k:
        filename = filePath+'\\'+file
        print(filename)

方法二:

import os

path = r'C:\Users\Administrator\Desktop\hunman'
dirs = os.listdir(path)
# print(dirs)
for file in dirs:
    filename = imgPath +'\\'+ file
    print(filename)
    

你可能感兴趣的:(python)