write a program to display all the files from the current
directory which are created in particular month
Answer Posted / rakesh
#include<stdio.h>
#include<stddef.h>
#include<dirent.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<time.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
char in[100],st[100],*ch,*ch1,c,buff[512];
DIR *dp;
int i;
struct dirent *ep;
struct stat sb;
char mon[100];
dp=opendir("./");
if(dp!=NULL)
{
while(ep=readdir(dp))
{
if(stat(ep->d_name,&sb)==-1)
{
perror("stat");
exit(EXIT_SUCCESS);
}
strcpy(mon,ctime(&sb.st_ctime));
ch=strtok(mon," ");
ch=strtok(NULL,",");
ch1=strtok(ch," ");
if((strcmp(ch1,argv[1]))==0)
{
printf("%s \t\t %s",ep->d_name,ctime(&sb.st_ctime));
}
}
(void)closedir(dp);
}
return 0;
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What is inside a seashell?
What happens on a system call?
madhar chod unix ke 10 commands dhang se likh nahi sakta hai
What is option in shell script?
How do we create command aliases in a shell?
Set up a Sev 2 alert when the Primary WA service fails. A windows batch script needs to be created that will monitor the WA service on the Primary and when the service stops/fails a Sev 2 TT is generated for a particular team ?
Explain about gui scripting?
How do I run a .sh file?
What happens when you type ls?
Write a command sequence to find the count of each word?
What is the lifespan of a variable inside a shell script?
How do I debug a shell script?
How do I run a bin bash script?
What is the way to do multilevel if-else's in shell scripting?
How to pass an argument to a script?