"This is the code. What is the meaning of '.' inside "opendir('.')" Does it specifies to the current directory?"
#include <stdio.h>
#include <dirent.h>
int main(void)
{
struct dirent *de; // Pointer for directory entry
// opendir() returns a pointer of DIR type.
DIR *dr = opendir(".");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return 0;
}
while ((de = readdir(dr)) != NULL)
printf("%s\n", de->d_name);
closedir(dr);
return 0;
}
This isn't really programming-related, but more OS-related.
On most operating systems the filesystem have the concept of parent directory and current directory.
The parent directory is commonly using the notation .., while the current directory is using the notation ..
So what opendir(".") will do is to open the current directory.
And as mentioned in a comment, the "current" directory doesn't have to be the directory where the executable program is residing. It's the current working directory for the process, which could be different. It depends on how and where the program was started, and if the program changes its own working directory (which the program in the question doesn't).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With