f_unlink空でないフォルダの削除


f_unlink空でないフォルダの削除


f_unlinkが空でないフォルダを削除するときは、フォルダの下の各ファイルを削除する必要があります.これは私がネット上で見つけたコードデバッグに問題があります.少し修正したバージョンです.親測はこの既定機能を実現し、特に記録することができます.
FRESULT FS_DeleteIntFile(INT8S* path)
{
    UINT i, j;
    FRESULT res;
    DIR dir;
    FILINFO fno;
    INT8S* path1;

#if _USE_LFN
    fno.lfname = 0; /* Set null pointer because LFN is not needed */
#endif
    res = f_opendir(&dir, path);
    if (res == FR_OK)
    {
        for (i = 0; path[i]; i++)
        {
          path1[i]=path[i];
        } 
        path1[i++] = '/';
        for (;;)
        {
            res = f_readdir(&dir, &fno);
            if (res != FR_OK || !fno.fname[0]) break;
            if (fno.fname[0] == '.') continue;
            j = 0;
            do
            path1[i+j] = fno.fname[j];
            while (fno.fname[j++]);
            if (fno.fattrib & AM_DIR)
            {
                res = FS_DeleteIntFile(path1);
                if (res != FR_OK) break;
            }
            res = f_unlink(path1);

            if ((res != FR_OK) && (res != FR_DENIED)) break;
        }
        path1[--i] = '\0';
    }##  
    return res;
}

/*   */
FRESULT FS_DeleteFolderOrFile(INT8S* path)
{
    FRESULT res;

    /*   */
    res = FS_DeleteIntFile(path);

    if (res == FR_OK)
    {
        /*   */
        res = f_unlink(path);
    }
    else if (FR_NO_PATH == res)
    {
        /*   */
        res = f_unlink(path);
    }
   
    return res;
}