|
Home > Archive > Unix questions > October 2005 > reading directory
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| hirenshah.05@gmail.com 2005-10-26, 2:49 am |
| Hi,
I want read directory and print all regular files. I tried using
S_ISREG, but it is not working. If I use IS_DIR it is printing all file
names.
here is my program
-------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<dirent.h>
#include<sys/stat.h>
int main()
{
int c;
DIR *dp;
struct dirent *dirp;
struct stat buf;
dp=opendir("/home/hiren/new/");
while((dirp= readdir(dp))!=NULL)
{
lstat(dirp->d_name,&buf);
if(S_ISREG(buf.st_mode))
printf("%s",dirp->d_name);
}
closedir(dp);
}
-----------------------------------------------------------------
| |
| Barry Margolin 2005-10-27, 2:48 am |
| In article <1130297913.093198.43620@g43g2000cwa.googlegroups.com>,
"hirenshah.05@gmail.com" <hirenshah.05@gmail.com> wrote:
> Hi,
>
> I want read directory and print all regular files. I tried using
> S_ISREG, but it is not working. If I use IS_DIR it is printing all file
> names.
Someone answered this already in another newsgroup. If a question is
*really* appropriate for multiple groups, please cross-post properly
(post a single message with all the groups in the "Newsgroups:" line).
However, in this case, the comp.unix.programmer group is really the only
appropriate group, so it's not necessary to send to multiple groups at
all.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
|
|
|
|
|