Opendir

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions 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 directory and it should not show the hidden files in the directory.
# 2  
Old 12-06-2012
Hello!

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

Quote:
RULES OF THE UNIX AND LINUX FORUMS


(1) No flames, shouting (all caps), sarcasm, bullying, profanity or arrogant posts.

(2) No negative comments about others or impolite remarks. Be patient.

(3) Refrain from idle chatter that does not contribute to the knowledge base. This does not apply to the forums in The Unix Lounge which are for off-topic discussions.

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.

(5) Search the forums database with your keywords before asking.

(6) Do not post classroom or homework problems.

(7) No job postings from headhunters or recruiters except in The Unix Forums Job Board. See How to Post to The UNIX Forums Job Board for information on using the Job Board.

(8) No BSD vs. Linux vs. Windows or similar threads.

(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.

(10) Don't post your email address and ask for an email reply. Don't send a private message with a technical question. The forums are for the benefit of all, so all Q&A should take place in the forums.

(11) Post questions with descriptive subjects. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

(12) These are not hacker boards so hacker related posts will be promptly deleted or moderated.

(13) The forum administrators reserve the right to prune, move or edit posts that do not adhere to the rules or are technically inaccurate.

(14) The forum administrators reserve the right to remove users or change their posting status to read only without notice if any rules are not followed.

(15) No smoking in the forums.
Cheers.

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

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

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