showtree wyswietla cala zawartosc

This commit is contained in:
Jakub Adamski 2019-01-13 16:47:33 +01:00
parent 3db7748748
commit 73b9b7d679
4 changed files with 13 additions and 11 deletions

View File

View File

Binary file not shown.

View File

@ -96,28 +96,30 @@ void tree (char **argv, char * directory){
if (fork() == 0){ if (fork() == 0){
DIR *d; DIR *d;
struct dirent *ent; struct dirent *ent;
char ndr[max], lastdir[max]; char ndr[max];
strcpy(ndr, directory); strcpy(ndr, directory);
while(1){ if ((d = opendir(ndr)) != NULL){ /*wchodzimy do katalogu*/
strcpy(lastdir, ndr); while ((ent = readdir(d)) != NULL){ /*czytamy zawartosc*/
if ((d = opendir(ndr)) != NULL){ /*wchodzimy do katalogu*/ char *name = ent->d_name;
while ((ent = readdir(d)) != NULL){ /*czytamy zawartosc*/ if (!(!strcmp(name, ".") || !strcmp(name, ".."))){ /*jesli nazwa rozna od . lub .. */
char *name = ent->d_name; if (fork()==0){
if (!(!strcmp(name, ".") || !strcmp(name, ".."))){ /*jesli nazwa rozna od . lub .. */
if (chdir(name) == 0){ /*udalo nam sie wejsc do katalogu*/ if (chdir(name) == 0){ /*udalo nam sie wejsc do katalogu*/
closedir(d); closedir(d);
printf("Katalog: %s\n", name); printf("Katalog: %s\n", name);
getcwd(ndr, sizeof(ndr)); /*zmieniamy directory*/ getcwd(ndr, sizeof(ndr)); /*zmieniamy directory*/
break; /*break czytanie poprzedniego katalogu*/ d = opendir(ndr);
} }
else else{
printf("Plik: %s\n", name); printf("Plik: %s\n", name);
exit(0);
}
} }
else
wait(NULL);
} }
} }
if (!strcmp(lastdir, ndr)) closedir(d);
break; /*jezeli nie zmienilismy kat to wychodzimy zeby nie czytac tego samego jeszcze raz*/
} }
exit(0); exit(0);
} }