C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-22-2003, 11:23 AM   #1
Registered User
 
Join Date: Apr 2003
Posts: 4
Code to display files and sizes of any folder

I have this code:

/*DIR.c */
#include <sys/types.h>
#include <sys/dir.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#define MAXPATH 255

void Error(char* msg)
{
perror(msg);
exit(0);
}

main(int argc,char** argv)
{
DIR *dhandle
struct direct *entry
struct stat inode;
char path[MAXPATH];

if (argc !=2) {Error("syntax: DIR directoryName"); }
dhandle=opendir(argv[1]);
if (dhandle==0) {Error("Open: "); }
printf("Listing of directory: %s\n inode name\n",argv[1]);

while ((entry=readdir(dhandle))!=0)

{

sprintf(path,"%s/%s",argv[1],entry->d_name);
if (stat(path,&inode)==-1) {Error("Getting inode: "); }

printf("%16u %-24s", entry->d_ino, entry->d_name);

if (S_ISREG(inode.st_mode)) printf("\tFile \n");

else

if (S_ISDIR(inode.st_mode)) printf("\tDirectory \n");

else printf("\tOther \n");

}

closedir(dhandle);

}

Now I'm trying to amend it from dir.c to dird.c so that the command dird pathname will print the total number of files in pathname, total number of blocks allocated and total number of bytes they consume. Any help please?

Thanks
CrackDown is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Prob with padding in BMP image files tin Game Programming 2 01-09-2006 08:23 AM


All times are GMT -6. The time now is 01:30 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22