user2321611
user2321611

Reputation: 1079

Reading file names from a directory

I'm reading all file names from a certain directory using this function:

void getdir(std::string dir, std::list<std::string>& files)
{
    DIR *dp;
    struct dirent *dirp;

    if((dp  = opendir(dir.c_str())) == NULL)
    {
        std::cout<< "Error: path "  << dir << " onbekend!\n";
    }
    else
    {
        while ((dirp = readdir(dp)) != NULL)
        {
            files.push_back(std::string(dirp->d_name));
        }
        closedir(dp);
    }
}

When I print them out, I get '.' or '..' too with the filenames. But the file '.' or '..' is not in the directory. I'm using ubuntu 12.04 :)

Upvotes: 0

Views: 116

Answers (1)

Uri Y
Uri Y

Reputation: 850

. is current directory, and .. is parent directory, you will find them in every directory.

Upvotes: 1

Related Questions