<div dir="ltr"><br><a href="http://stackoverflow.com/questions/12489/how-do-you-get-a-directory-listing-in-c">http://stackoverflow.com/questions/12489/how-do-you-get-a-directory-listing-in-c</a><br><br><br>here is how I done it on NT long ago<br><br>//cgidir copyright 1996 Billy Stiltner<br>#include <stdio.h><br>#include "g:\bc45\cgic\cgic105\cgic.h"<br>#include <dir.h><br>#include <dos.h><br>FILE *in, *out;<br> struct ffblk f;<br> char drive[3],dir[66],name[9],ext[5];<br> int done;<br><br> char pathname[81];<br>char ConfigUrl[255];<br> char ConfigDir[255];<br> int cgiMain() {<br>#if DEBUG<br> /* Load a saved CGI scenario if we're debugging */<br> cgiReadEnvironment("/home/boutell/public_html/capcgi.dat");<br>#endif<br><br><br> cgiHeaderContentType("text/html");<br><br> /*cgiHeaderLocation("<a href="http://206.151.77.100/output.htm">http://206.151.77.100/output.htm</a>");*/<br> fprintf(cgiOut, "<HTML><HEAD>\n");<br> fprintf(cgiOut, "<TITLE>Stiltner's Web Directory</TITLE></HEAD>\n");<br> fprintf(cgiOut, "<BODY>Stiltner's Web Directory Copyright 1996 Billy Stiltner<BR>\n");<br><br><br>if((in = fopen("\\cgidir\\cgidir.cfg", "r+")) == NULL)<br> {
<br> fprintf(cgiOut, "Cannot open configuration file.\n");
<br> return 1;
<br> }else{
<br> fgets(ConfigUrl,255,in);<br> fgets(ConfigDir,255,in);<br> fprintf(cgiOut,ConfigUrl);<br> fprintf(cgiOut,ConfigDir);<br>// fprintf(cgiOut, "<form method=\"POST\" action=\"<a href="http://206.151.77.100/scripts/cgidir.exe\">http://206.151.77.100/scripts/cgidir.exe\</a>">");<br> fprintf(cgiOut, "<form method=\"POST\" action=");<br> fprintf(cgiOut, ConfigUrl);<br> fprintf(cgiOut, ">");<br> };<br><br><br><br> fprintf(cgiOut, "<HR><BR>\n");<br><br><br><br><br> cgiFormStringNoNewlines("pathname", pathname, 81);<br> fprintf(cgiOut, "Directory of %s<BR>\n", pathname);<br> fprintf(cgiOut, "<HR>");<br> done = findfirst(pathname,&f,63);<br> while (!done)<br> {
<br> fnsplit(f.ff_name,drive,dir,name,ext);
<br> if(f.ff_attrib==FA_DIREC){
<br> fprintf(cgiOut,"<IMG SRC=\"/dir.gif\" HEIGHT=13 WIDTH=15>");
<br> }else{
<br> fprintf(cgiOut,"<IMG SRC=\"/file.gif\" HEIGHT=16 WIDTH=13>");};
<br> <br> fprintf(cgiOut, f.ff_name);
<br> fprintf(cgiOut, "<BR>\n");
<br> <br> done = findnext(&f);
<br> }<br> fprintf(cgiOut, "<HR>");<br><br> fprintf(cgiOut, "Path:<input type=\"text\" name=\"pathname\"><BR>\n<BR>\n");<br> fprintf(cgiOut, "<input type=\"submit\" name=\"submit1\" value=\"Get Directory\">");<br> <br>fprintf(cgiOut, "</form>");<br> fprintf(cgiOut, "</BODY></HTML>\n");<br> return 0;<br>}<br><br><br></div>