其他分享
首页 > 其他分享> > os.mkdir FileNotFoundError: [Errno 2] No such file or directory:

os.mkdir FileNotFoundError: [Errno 2] No such file or directory:

作者:互联网

今天在创建文件夹时遇到了

img_txt_path = img_path.replace(img_path.split("/")[0],"./txt")
txt_path = img_txt_path+"_txt"
if not os.path.isdir(txt_path):
	os.mkdir(txt_path)

Error

FileNotFoundError: [Errno 2] No such file or directory: './txt/data/917/62/0__1_txt'

原因是os.mkdir 只能生成下一级的目录文件. 若要想生成多个子路径下的文件,需要将os.mkdir 改成 os.makedirs

img_txt_path = img_path.replace(img_path.split("/")[0],"./txt")
txt_path = img_txt_path+"_txt"
if not os.path.isdir(txt_path):
	os.makedirs(txt_path)

标签:img,No,Errno,FileNotFoundError,mkdir,path,txt,os
来源: https://blog.csdn.net/wangweiwells/article/details/87900218