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)
上一篇:使用git clone 报错curl56 errno 10054解决方法


下一篇:mysqlG基于TID模式同步报错 (Last_IO_Errno: 1236)