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);
}
void ptab (int ile){
int i;
for (i=0; i<ile; i++)
printf(" |");
}
void tree (char **argv, char * directory){
if (argv[1] != NULL && argv[2] != NULL){
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;
struct dirent *ent;
char ndr[max];
int tab = 0;
strcpy(ndr, directory);
if ((d = opendir(ndr)) != NULL){ /*wchodzimy do katalogu*/
@ -106,12 +113,15 @@ void tree (char **argv, char * directory){
if (fork()==0){
if (chdir(name) == 0){ /*udalo nam sie wejsc do katalogu*/
closedir(d);
printf("Katalog: %s\n", name);
ptab(tab);
printf("\033[1;34m%s\033[0m\n", name);
getcwd(ndr, sizeof(ndr)); /*zmieniamy directory*/
d = opendir(ndr);
tab++;
}
else{
printf("Plik: %s\n", name);
ptab(tab);
printf("%s\n", name);
exit(0);
}
}