http://stackoverflow.com/questions/12489/how-do-you-get-a-directory-listing-in-c


here is how I done it on NT long ago

//cgidir copyright 1996 Billy Stiltner
#include <stdio.h>
#include "g:\bc45\cgic\cgic105\cgic.h"
#include <dir.h>
#include <dos.h>
FILE *in, *out;
    struct ffblk f;
  char drive[3],dir[66],name[9],ext[5];
  int done;

  char pathname[81];
char ConfigUrl[255];
  char ConfigDir[255];
  int cgiMain() {
#if DEBUG
    /* Load a saved CGI scenario if we're debugging */
    cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");
#endif


    cgiHeaderContentType("text/html");

  /*cgiHeaderLocation("http://206.151.77.100/output.htm");*/
    fprintf(cgiOut, "<HTML><HEAD>\n");
    fprintf(cgiOut, "<TITLE>Stiltner's Web Directory</TITLE></HEAD>\n");
    fprintf(cgiOut, "<BODY>Stiltner's Web Directory Copyright 1996 Billy Stiltner<BR>\n");


if((in = fopen("\\cgidir\\cgidir.cfg", "r+"))     == NULL)
    {
    fprintf(cgiOut, "Cannot open configuration file.\n");
    return 1;
    }else{
            fgets(ConfigUrl,255,in);
            fgets(ConfigDir,255,in);
            fprintf(cgiOut,ConfigUrl);
            fprintf(cgiOut,ConfigDir);
//   fprintf(cgiOut, "<form method=\"POST\" action=\"http://206.151.77.100/scripts/cgidir.exe\">");
 fprintf(cgiOut, "<form method=\"POST\" action=");
 fprintf(cgiOut, ConfigUrl);
 fprintf(cgiOut, ">");
            };



    fprintf(cgiOut, "<HR><BR>\n");




    cgiFormStringNoNewlines("pathname", pathname, 81);
    fprintf(cgiOut, "Directory of  %s<BR>\n", pathname);
    fprintf(cgiOut, "<HR>");
    done = findfirst(pathname,&f,63);
    while (!done)
    {
    fnsplit(f.ff_name,drive,dir,name,ext);
    if(f.ff_attrib==FA_DIREC){
      fprintf(cgiOut,"<IMG SRC=\"/dir.gif\" HEIGHT=13 WIDTH=15>");
        }else{
         fprintf(cgiOut,"<IMG SRC=\"/file.gif\" HEIGHT=16 WIDTH=13>");};
 
 fprintf(cgiOut, f.ff_name);
 fprintf(cgiOut, "<BR>\n");
 
        done = findnext(&f);
    }
       fprintf(cgiOut, "<HR>");

    fprintf(cgiOut, "Path:<input type=\"text\" name=\"pathname\"><BR>\n<BR>\n");
  fprintf(cgiOut, "<input type=\"submit\" name=\"submit1\" value=\"Get Directory\">");
 
fprintf(cgiOut, "</form>");
    fprintf(cgiOut, "</BODY></HTML>\n");
    return 0;
}