?
Solved

Accessing directory listing.

Posted on 1998-11-30
2
Medium Priority
?
273 Views
Last Modified: 2010-04-21
How can I access the directory listing using system calls? I wanted to write a program when given a directory name prints all the files in it?
0
Comment
Question by:vividh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Expert Comment

by:seedy
ID: 2008151
Use opendir, readdir, closedir and other related routines.  These are part of the standard library routines.  Here is a sample code that prints the names  of  all  the files in the current directory: (taken from the man pages)

#include <stdio.h>
#include <dirent.h>

main()
{
       DIR *dirp;
       struct dirent *direntp;

       dirp = opendir( "." );
       while ( (direntp = readdir( dirp )) != NULL )
               (void)printf( "%s\n", direntp->d_name );
       (void)closedir( dirp );
       return (0);
}

Some flavors of UNIX may also have getdents or getdirentries; read man pages for more info.

0
 

Accepted Solution

by:
rajeevm earned 200 total points
ID: 2008152
Can you please try ls -R option , and if you want to write a program , then use system function and invoke the above command .
I think it will solve your problem
Thanks & Regards,
Rajeev Mishra
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question