/* Write C program that display name of all empty file and remove from directory */
#include
#include
#include
int main()
{
DIR *dp=opendir(".");
struct dirent *files;
struct stat stbuf;
int siz=0,cnt=0;
while((files=readdir(dp))!=NULL)
{
if(lstat(files->d_name,&stbuf)==-1)
{
printf("cant link");
}
else
{
if(S_ISREG(stbuf.st_mode))
{
siz=(int)stbuf.st_size;
if(siz==0)
{
printf(" %s is empty file of size= %d \n",files->d_name,siz);
//remove(files->d_name);
unlink(files->d_name);
cnt++;
}
}
}
}
printf("\n number of empty file %d",cnt);
return 0;
}
#include
#include
#include
int main()
{
DIR *dp=opendir(".");
struct dirent *files;
struct stat stbuf;
int siz=0,cnt=0;
while((files=readdir(dp))!=NULL)
{
if(lstat(files->d_name,&stbuf)==-1)
{
printf("cant link");
}
else
{
if(S_ISREG(stbuf.st_mode))
{
siz=(int)stbuf.st_size;
if(siz==0)
{
printf(" %s is empty file of size= %d \n",files->d_name,siz);
//remove(files->d_name);
unlink(files->d_name);
cnt++;
}
}
}
}
printf("\n number of empty file %d",cnt);
return 0;
}
Comments
Post a Comment