FRESULT folder_create(char* path)
{
FRESULT res;
DIR dir;
char *str = path;
char *pbuf;
u16 cnt=0;
res = f_opendir(&dir, path);
if (res == FR_OK)
{
f_closedir(&dir);
return FR_OK;
}
else
{
pbuf=mymalloc(SRAMIN,200);
if(pbuf==NULL)
return FR_NOT_ENOUGH_CORE;
while(*str !=0)
{
if(*str=='/')
{
memset(pbuf,0x00,200);
memcpy(pbuf,path,cnt);
printf("%s\r\n",pbuf);
if(f_opendir(&dir, pbuf)==FR_NO_PATH)
f_mkdir(pbuf);
else
f_closedir(&dir);
}
cnt++;
str++;
}
myfree(SRAMIN,pbuf);
res = f_mkdir(path);//创建最后一级目录
}
return res;
}
调用方法:
folder_create("0:/ccc/x1/x2/x3/x4/x5/x6/x7/x8");
|