home *** CD-ROM | disk | FTP | other *** search
- #include <fcntl.h>
- #include <dir.h>
- #include <dos.h>
- #include <io.h>
- #include <stdio.h>
-
- #define TRUE 1
- #define FALSE 0
- #define MAX_DIRS 500
-
- typedef struct {
- char name[80];
- char status;
- } DIRECT_ORY;
-
- struct ffblk buf;
- int done;
- DIRECT_ORY directory[MAX_DIRS];
-
- char Path[80];
- char Search_Path[80];
- char Attributes[6];
- char *directory_name = "\0";
- char *complete_dir = "\0";
- char *complete_file = "\0";
-
- FILE *fd;
- int direct_ctr = 1;
- int save_direct_ctr;
- int array_ctr;
- int print_ctr;
- int ctl_state = TRUE;
- int found_new = FALSE;
- int directory_counter = 0;
- int file_counter = 0;
- /* Declarations End */
-
- /* Main program flow begins here */
- main ()
- {
-
- if (!get_directories()) {
- printf("Program aborted in get_directories function...\n");
- exit(1);
- }
- print_directories();
- if (!get_files()) {
- printf("Program aborted in get_files function...\n");
- exit(2);
- }
- printf("There are %d directories...\n",directory_counter);
- printf("There are %d files...\n\n\n",file_counter);
- printf(" ...Program completed successfully...\n");
- /* END OF MAIN */
- }
-
- int get_directories()
- {
- printf("Gathering directory names...\n\n");
- directory[0].status = 'n';
- strcpy(directory[0].name,"\\");
- while (ctl_state) {
- save_direct_ctr = direct_ctr;
- for (array_ctr = 0;array_ctr < save_direct_ctr;array_ctr++) {
- found_new = FALSE;
- if (directory[array_ctr].status == 'n') {
- found_new = TRUE;
- if (array_ctr == 0) {
- strcpy(Path,directory[array_ctr].name);
- strcpy(Search_Path,Path);
- strcat(Search_Path,"*.*");
- }
- else {
- strcpy(Path,directory[array_ctr].name);
- strcat(Path,"\\");
- strcpy(Search_Path,Path);
- strcat(Search_Path,"*.*");
- }
- done = findfirst(Search_Path,&buf,0x3f);
- while (done == 0) {
- if (buf.ff_attrib & FA_DIREC) {
- if (direct_ctr > MAX_DIRS) {
- printf("Array Overflow...\n");
- return(FALSE);
- }
- if (real_dir(buf.ff_name)) {
- directory[direct_ctr].status = 'n';
- strcpy(directory[direct_ctr].name,Path);
- strcat(directory[direct_ctr].name,buf.ff_name);
- strcpy(directory_name,directory[direct_ctr].name);
- direct_ctr++;
- }
- }
- done = findnext(&buf);
- }
- directory[array_ctr].status = 'o';
- }
- }
- if (!found_new)
- ctl_state = FALSE;
- }
- return(TRUE);
- }
-
- int print_directories()
- {
- printf("Printing directory names to file: dir.lst...\n\n");
- if ((fd = fopen("dir.lst","w")) == NULL) {
- printf("Error opening dir.lst for writing...\n");
- return(FALSE);
- }
- for (print_ctr = 0;print_ctr < direct_ctr;print_ctr++) {
- strcpy(complete_dir,directory[print_ctr].name);
- strcat(complete_dir,"\n");
- fputs(complete_dir,fd);
- directory_counter++;
- }
- fclose(fd);
- return(TRUE);
- }
-
- int real_dir(current_name)
- char current_name[];
- {
- if (current_name[0] == '.' &&
- (current_name[1] == '\0' || current_name[1] == '.'))
- return(FALSE);
- else
- return(TRUE);
- }
- int get_files()
- {
- printf("Gathering file names...\n");
- printf(" and printing to file: file.lst...\n\n");
- if ((fd = fopen("file.lst","w")) == NULL) {
- printf("Error opening file.lst for writing...\n");
- return(FALSE);
- }
- for (array_ctr = 0;array_ctr < direct_ctr;array_ctr++) {
- if (array_ctr == 0) {
- strcpy(Path,directory[array_ctr].name);
- strcpy(Search_Path,Path);
- strcat(Search_Path,"*.*");
- }
- else {
- strcpy(Path,directory[array_ctr].name);
- strcat(Path,"\\");
- strcpy(Search_Path,Path);
- strcat(Search_Path,"*.*");
- }
- done = findfirst(Search_Path,&buf,0x3f);
- while (done == 0) {
- if (buf.ff_attrib != 16) {
- if (buf.ff_attrib == 0)
- Attributes[0] = 'N';
- else
- Attributes[0] = ' ';
- if (buf.ff_attrib & FA_RDONLY)
- Attributes[1] = 'R';
- else
- Attributes[1] = ' ';
- if (buf.ff_attrib & FA_HIDDEN)
- Attributes[2] = 'H';
- else
- Attributes[2] = ' ';
- if (buf.ff_attrib & FA_SYSTEM)
- Attributes[3] = 'S';
- else
- Attributes[3] = ' ';
- if (buf.ff_attrib & FA_ARCH)
- Attributes[4] = 'A';
- else
- Attributes[4] = ' ';
- strcpy(Attributes[5],'\0');
- strcpy(complete_file,Attributes);
- strcat(complete_file," - ");
- strcat(complete_file,Path);
- strcat(complete_file,buf.ff_name);
- strcat(complete_file,"\n");
- fputs(complete_file,fd);
- file_counter++;
- }
- done = findnext(&buf);
- }
- }
- fclose(fd);
- return(TRUE);
- }