python如何读取文件夹下的子文件夹
生活随笔
收集整理的這篇文章主要介紹了
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如何读取文件夹下的子文件夹的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 相机无法对焦的原因(2023相机推荐)
- 下一篇: python 如何将代码中的输入保存到t