This post was published long ago, when I was a student and an amateur blogger. The links might be outdated and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
[Click Here to get other programs by email ]
………………………………………………………………………………………………………………………….
PART -B
………………………………………………………………………………………………………………………….
6b) C program that accepts a valid directory names as a command line argument and lists all the files in the given directory as well as all the subsequent subdirectories. (The solution can be recursive or nonrecursive).
#include<stdio.h>
#include<ftw.h>
int recursive(const char *dir,const struct stat *name,int type)
{
if(type==FTW_D)
printf(“n Directory->%s”,dir);
else if(type==FTW_F)
printf(“nFile->%s”,dir);
return 0;
}
int main(int argc,char *argv[])
{
int depth=5;
ftw(argv[1],recursive,depth);
printf(“n”);
return 0;
}
Leave a ReplyCancel reply