C: _access_s() can't find the folder

时间:2018-12-03 13:20:57

标签: c filesystems access

This is a structure of a location where is the application executed: enter image description here

The purpose of an application is to check if there is the folder named Folder. This is a function that is responsible for this:

bool Initialize(const char * c_pszFolder)
{
    if (_access_s(c_pszFolder, 00) != 0)
    {
        printf("Error! Folder doesn't exist.");
        return false;
    }

    printf("Success! Folder does exist.");
    return true;
}

Here is how the function is called:

int main()
{
    Initialize("Folder");
}

According to a documentation the second argument of _access_s() is the number of a case you want to test. In my case I would use: 00 Existence only.. Although, when I run the application the app return false, which is really confusing due to results of debugging: enter image description here

After trying to get more information by using _get_errno() I've got errno value 2, which stands for: ENOENT No such file or directory. But the folder exists.

1 个答案:

答案 0 :(得分:2)

只需更改当前目录

Project | Properties | Select Configuration | Configuration Properties | Debugging | Working directory