I’m trying to get a file list excluding diretories like “.” and “..”.
I use the following code to do that:
DIR *dir;
struct dirent *ent;
dir = opendir(currentDir);
if (dir != NULL)
{
while ((ent = readdir (dir)) != NULL)
{
if (ent->d_name == "." || ent->d_name == "..")
{
continue;
}
}
}
But it doesn’t work.
You should be using
strcmpto compare strings. Rather than this:you need this:
Your code is comparing the pointers directly, rather than comparing the content of the strings.
See the strcmp documentation for more information.