python如何读取文件夹下的子文件夹

import os
# 创建文件夹
def mkdir(path):
    if(os.path.exists(path)==False):
        os.mkdir(path)
    else:
        pass
# 根目录
root_path = 'C:/Users/man.wang/Desktop/key_point_vis/'
img_path = root_path + 'img/'
xml_path = root_path + 'xml/'
check_path = root_path + 'check/'
mkdir(check_path)
# 读取每个目录下的子文件夹
for img_list in os.listdir(img_path):
    imgOrdpath = img_path + img_list + '/'
    xmlOrdpath = xml_path + img_list.split('img')[0] + 'xml/'
    print(imgOrdpath,xmlOrdpath)
    saveImgpath = check_path + img_list + '_check_label/'
    saveVideopath = check_path + img_list + '_check_label.avi'
    mkdir(saveImgpath)

输出:

C:/Users/man.wang/Desktop/key_point_vis/img/20200303_front_carpoint_img/ 
C:/Users/man.wang/Desktop/key_point_vis/xml/20200303_front_carpoint_xml/

C:/Users/man.wang/Desktop/key_point_vis/img/20200303_left_carpoint_img/ 
C:/Users/man.wang/Desktop/key_point_vis/xml/20200303_left_carpoint_xml/

C:/Users/man.wang/Desktop/key_point_vis/img/20200303_right_carpoint_img/ 
C:/Users/man.wang/Desktop/key_point_vis/xml/20200303_right_carpoint_xml/

处理:

在这个for循环内进行操作

你可能感兴趣的:(python学习笔记)