showtree done
This commit is contained in:
parent
73b9b7d679
commit
c973dc63ae
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user