Opendir


 
Thread Tools Search this Thread
Top Forums Programming Opendir
# 1  
Old 12-06-2012
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 dir.
# 2  
Old 12-06-2012
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

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 : (1 Reply)
Discussion started by: console
1 Replies

2. Shell Programming and Scripting

PHP 5 solaris opendir failure

Hello! I've moved a web from my RHEL5 Apache/2.2.3 machine to a Sun Solaris 5.9 Apache/2.2.6 (Unix) PHP/5.2.5 mod_ssl/2.2.6 machine. The web worked just fine on the rhel5 machine and most of the php pages works fine on the solaris machine to but not the one where I read a directory and prints... (1 Reply)
Discussion started by: Esaia
1 Replies

3. Programming

opendir() + customly created directories

Gday all In a program I am designing, I am using opendir() to test whether entries under a certain directory are sub-directories or not. This method works fine for the directory itself (.) and the parent directory (..), however it does not work for any sub-directories I manually create. i.e.... (5 Replies)
Discussion started by: JamesGoh
5 Replies
Login or Register to Ask a Question