System Software Lab Programs ( UNIX Programs ) – 6b
// June 6th, 2009 // Educational, Engineering, Unix and System Software Lab
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;
}



