home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / imlib / port / dos4gw / jdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-23  |  918 b   |  45 lines

  1. #include <direct.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include "jmalloc.hpp"
  6.  
  7.  
  8. void get_directory(char *path, char **&files, int &tfiles, char **&dirs, int &tdirs)
  9. {
  10.   struct dirent *de;
  11.   files=NULL;
  12.   dirs=NULL;
  13.   tfiles=0;
  14.   tdirs=0;
  15.   DIR *d=opendir(path);
  16.   if (!d) return ;
  17.   char curdir[200];
  18.   getcwd(curdir,200);
  19.   chdir(path);
  20.  
  21.   do
  22.   {
  23.     de=readdir(d);
  24.     if (de)
  25.     {
  26.       if (de->d_attr&_A_SUBDIR)
  27.       {      
  28.     tdirs++;
  29.     dirs=(char **)jrealloc(dirs,sizeof(char *)*tdirs,"dir list");
  30.     dirs[tdirs-1]=strcpy((char *)jmalloc(strlen(de->d_name)+1,"tmp file name"),de->d_name);
  31.       } else
  32.       {
  33.     tfiles++;
  34.     files=(char **)jrealloc(files,sizeof(char *)*tfiles,"dir list");
  35.     files[tfiles-1]=strcpy((char *)jmalloc(strlen(de->d_name)+1,"tmp file name"),de->d_name);
  36.       }
  37.     }
  38.   } while (de);
  39.   closedir(d);
  40.   chdir(curdir);
  41. }
  42.  
  43.  
  44.  
  45.