Solved

Accessing directory listing.

Posted on 1998-11-30
2
259 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
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 100 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

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