DIRECTORY MANIPULATION- READ DIR,OPEN DIR

SOURCE CODE:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<sys/dir.h>
#define MAX CHARS 200
int char read, tmp;
struct direct *DirEntryPtr;
DIR *dirptr;
Struct stat Stat;
char path [MAX_CHARS];
main(argc,argc)
int argc;
char **argv
{
dirptr=opendir(argv[1]);
while(1)
DirEntryPtr=readdir(dirptr);
if(DirEntryPtr==0)
break;
if(strcmp(DirEntryPtr->d_name,”.”)!=0&&
strcmp(DirEntryPtr->d_name,”..”)
{
printf(“%s”, DirEntryPtr->d_name);
tmp=stat(path,&Stat)
if(S_ISDIR (Stat.st mode))
printf(“*”);
printf(“\n”);
}
}
}

OUTPUT:
[examuser35@localhost Jebastin]$ cc dm.c
[examuser35@localhost Jebastin]$ ./a.out
.a.sh.swp        b.c        r1
sf.sh            fm.c        dm.c
e.sh            c.c        r2
sw.sh            output 2    .dm.c.swp
fp.sh            c        .dm.c.swpo
df.sh            output1
a.out            r1
a.c            dm.c
b.c.swp        r2
c.sh            .dm.c.swp
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: