showtree wyswietla cala zawartosc
This commit is contained in:
parent
3db7748748
commit
73b9b7d679
0
Microshell/katalog/plik1.txt
Normal file
0
Microshell/katalog/plik1.txt
Normal file
0
Microshell/katalog/test/test.txt
Normal file
0
Microshell/katalog/test/test.txt
Normal file
Binary file not shown.
@ -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 (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{
|
||||
printf("Plik: %s\n", name);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("Plik: %s\n", name);
|
||||
wait(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strcmp(lastdir, ndr))
|
||||
break; /*jezeli nie zmienilismy kat to wychodzimy zeby nie czytac tego samego jeszcze raz*/
|
||||
closedir(d);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user