Opendir函数的路径是否为NULL?

时间:2019-03-29 07:40:03

标签: opendir dirent.h

我打算清除虚幻引擎4屏幕截图路径中的屏幕截图文件。 我用谷歌搜索,然后找到了一种清除路径下所有文件的解决方案。方法地址如下。我尝试了最有用的答案,然后为函数opendir(“ ...”)得到了NULL ptr。 我不确定路径是否由于格式无效。我希望任何人都可以帮助我找出函数“ opendir”中的正确路径。 谢谢。

How to delete all files in a folder, but not delete the folder using NIX standard libraries?

/ *文件夹的路径(我的opendir函数所需的路径)是:
D:\ Unreal Engine项目\ OutSourcingSuits \ Saved \ Screenshots \ Windows * /

/ *这是路径中的cpp代码:
D:\虚幻引擎项目\ OutSourcingSuits \ Source \ OutSourcingSuits * /

#include <stdio.h>
#include <dirent.h>

void UNetworkMgr::ClearFolder()
{
    char *folderpath = "/Saved/Screenshots/Windows";

    // These are data types defined in the "dirent" header
    DIR *theFolder = opendir(folderpath);
    struct dirent *next_file;
    char filepath[256];

    while (theFolder !=NULL && (next_file = readdir(theFolder)) != NULL)
    {
        // build the path for each file in the folder
        sprintf_s(filepath, "%s/%s", folderpath, next_file->d_name);
        remove(filepath);
    }
    closedir(theFolder);
    return;
}

0 个答案:

没有答案