#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include <conio.h>
#include <cstring.h>
char directory_name[128]; // maximum lenght is 128 as far as i had seen in
// win9x, but xp goes upto approx==231. dir length
char * view[] = {
"-----",
"-",
" -----",
" ",
" -----"
};
void TREE_TRAVERSE(char * );
int counter, sw = 0;
char current_working_directory[128];
void main() {
clrscr();
getcwd(current_working_directory, 128); // preserve curr. dir..
chdir("\\"); //to root , this is important
TREE_TRAVERSE("*.*"); // traverl...
chdir(current_working_directory); // store to present working directory...
}
void TREE_TRAVERSE(char * pointer) {
struct ffblk file;
int flag, num = 0, i, j;
static int deep_inside = 0;
flag = findfirst(pointer, & file, FA_DIREC); // find directory and not filez...
while (flag == 0) // loop until you are out
{
if ((file.ff_attrib & FA_DIREC) == FA_DIREC && file.ff_name[0] != '.') {
deep_inside++; // go into directory...
directory_name[0] = '\0';
if (deep_inside == 1) //if on root put "-"
strcat(directory_name, view[0]);
else {
strcat(directory_name, view[1]); //else decorate
i = 2;
while (i < deep_inside) // put space upto...
{
strcat(directory_name, view[3]); //3 for space
i++;
//
printf("%d", i);
}
if (i == 2) {
strcat(directory_name, view[4]);
}
//
if (i == 3) {
strcat(directory_name, view[1]);
strcat(directory_name, view[2]);
} //up dated
else {
strcat(directory_name, view[2]);
}
}
strcat(directory_name, file.ff_name);
printf("%s", directory_name); // print dir name
//if out of dir's then goto new line
if (num != deep_inside)
printf("\n"); //
getch();
chdir(file.ff_name);
file.ff_name[0] = '\0';
TREE_TRAVERSE(pointer);
} //e-o-if
flag = findnext( & file);
} // e-o-while
if (deep_inside--> 0)
chdir("..");
}