Solved

Accessing directory listing.

Posted on 1998-11-30
2
249 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now