![]() |
| | #1 |
| Registered User Join Date: Apr 2003
Posts: 4
| Code to display files and sizes of any folder /*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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |