showtree done

This commit is contained in:
Jakub Adamski 2019-01-14 12:54:39 +01:00
parent 73b9b7d679
commit c973dc63ae
2 changed files with 12 additions and 2 deletions

Binary file not shown.

View File

@ -83,6 +83,12 @@ void exe (char **argv){
wait(NULL); wait(NULL);
} }
void ptab (int ile){
int i;
for (i=0; i<ile; i++)
printf(" |");
}
void tree (char **argv, char * directory){ void tree (char **argv, char * directory){
if (argv[1] != NULL && argv[2] != NULL){ if (argv[1] != NULL && argv[2] != NULL){
printf("Too many arguments\nshowtree takes no arguments \nor exacly 1 argument for desired directory\n"); printf("Too many arguments\nshowtree takes no arguments \nor exacly 1 argument for desired directory\n");
@ -97,6 +103,7 @@ void tree (char **argv, char * directory){
DIR *d; DIR *d;
struct dirent *ent; struct dirent *ent;
char ndr[max]; char ndr[max];
int tab = 0;
strcpy(ndr, directory); strcpy(ndr, directory);
if ((d = opendir(ndr)) != NULL){ /*wchodzimy do katalogu*/ if ((d = opendir(ndr)) != NULL){ /*wchodzimy do katalogu*/
@ -106,12 +113,15 @@ void tree (char **argv, char * directory){
if (fork()==0){ if (fork()==0){
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); ptab(tab);
printf("\033[1;34m%s\033[0m\n", name);
getcwd(ndr, sizeof(ndr)); /*zmieniamy directory*/ getcwd(ndr, sizeof(ndr)); /*zmieniamy directory*/
d = opendir(ndr); d = opendir(ndr);
tab++;
} }
else{ else{
printf("Plik: %s\n", name); ptab(tab);
printf("%s\n", name);
exit(0); exit(0);
} }
} }