Opendir

code:
#include<iostream>
#include <dirent.h>
using namespace std;
int main()
{

DIR*dir;
dir = opendir("/");
if (dir !=NULL)
{
struct dirent * abcd;
while ((abcd=readdir (dir))!=NULL)
{
cout << abcd -> d_name;
}
}}
output : this gives the output of Directory "/"

ques :
what if i wanted to let user make an input of Directory name of there choice and if the directory name is not there program should show the contents of current directory and it should not show the hidden files in the directory.

Hello!

In case you forgot to read the forum rules, here is quick copy.

Cheers.

The UNIX and Linux Forums