home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / OOPWLD.ZIP / DIRECT / DIRECT.HPP next >
Encoding:
C/C++ Source or Header  |  1990-06-10  |  1.4 KB  |  52 lines

  1. // DIRECT.HPP : objects to store file directory information
  2. #include <dos.h>
  3. #include <dir.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6.  
  7. class dirfile {
  8. protected:  // means derived classes have access
  9.   char filename[14];
  10.   char filepath[MAXPATH];
  11.   long size;
  12.   char attribute;
  13.   int time, date;
  14. public:
  15.   dirfile() { // constructor
  16.     size = 0L;
  17.     attribute = 0;
  18.     time = date = 0;
  19.     filename[0] = '\0';  // null-terminated string
  20.     filepath[0] = '\0';
  21.   }
  22.   // No destructor (cleanup) needed here.
  23.   void setfile(ffblk * file_info) {
  24.     strcpy(filename, file_info->ff_name);
  25.     size = file_info->ff_fsize;
  26.     attribute = file_info->ff_attrib;
  27.     time = file_info->ff_ftime;
  28.     date = file_info->ff_fdate;
  29.     getcwd(filepath, MAXPATH);
  30.   }
  31.   int print() {
  32.     if(attribute & FA_DIREC) 
  33.       return printf("subdirectory: %s\\%s\n", filepath, filename);
  34.     if(size)
  35.       return printf("%s\\%s  %ld bytes\n", filepath, filename, size);
  36.     return 0;
  37.   }
  38.   int fsize() { return size; }  // access function
  39.   // a second way to print a file:
  40.   void print2() {
  41.     if(!*filename) return;  // don't print empty objects
  42.     if(attribute & FA_DIREC) { // print directories with a '\'
  43.       char buf[14];
  44.       strcpy(buf, filename);
  45.       strcat(buf, "\\");
  46.       printf("%-15s", buf);
  47.       return;
  48.     }
  49.     printf("%-15s", filename);
  50.   }
  51. };
  52.