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