#include #include #include #include #include #include #include typedef struct set{ char path[PATH_MAX]; char name[PATH_MAX]; mode_t mode; struct set *next; } set; void procFile(set *s){ char st[2*PATH_MAX]; sprintf(st,"%s/%s",s->path,s->name); printf("Datei %s\n",st); } int compare(set *s1, set *s2){ int r; r=s1->mode-s2->mode; if(r) return r; r=strcmp(s1->name,s2->name); return r; } void procDir(char *rootDir){ DIR *di; struct dirent *d; char st[2*PATH_MAX]; struct stat sb; struct set *root, *prev,*act,*next; root=0; printf("Verzeichnis %s\n",rootDir); di=opendir(rootDir); if(!di) return; while(d=readdir(di)){ if(d->d_name[0]!='.'){ sprintf(st,"%s/%s",rootDir,d->d_name); stat(st,&sb); //printf("%d %s\n",sb.st_mode&S_IFMT,st); next=calloc(1,sizeof(set)); if(!next){ printf("Speichermangel!\n"); exit(0); } next->mode=sb.st_mode&S_IFMT; strcpy(next->path,rootDir); strcpy(next->name,d->d_name); prev=0; act=root; while(act){ if(compare(act,next)>0) break; prev=act; act=act->next; } if(prev) prev->next=next; else root=next; next->next=act; } } closedir(di); //printf("Ausgabe:\n"); while(root){ next=root->next; //printf("%d %s\n",root->mode,root->name); sprintf(st,"%s/%s",rootDir,root->name); if((root->mode)==S_IFREG) procFile(root); if((root->mode)==S_IFDIR){ procDir(st); } free(root); root=next; } } int main(int argc, char **argv){ if(argc<2) return -1; procDir(argv[1]); printf("fertig.\n"); return 0; }