diff --git a/Microshell/katalog/plik1.txt b/Microshell/katalog/plik1.txt new file mode 100644 index 0000000..e69de29 diff --git a/Microshell/katalog/test/test.txt b/Microshell/katalog/test/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/Microshell/microshell b/Microshell/microshell index 1806f22..313a64a 100755 Binary files a/Microshell/microshell and b/Microshell/microshell differ diff --git a/Microshell/microshell.c b/Microshell/microshell.c index 69f8bcd..8258771 100644 --- a/Microshell/microshell.c +++ b/Microshell/microshell.c @@ -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); }