🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1199

Re: WANTED: Code to search DOS directory/subdirectories

#1199
From: N7YVM
Date: Tue, 01 Sep 1992 17:56
90 lines
2848 bytes
Heres a little bit of code I wrote to search dir trees for file specs... Its worked well for quite a while...
I used to use norton for this, but it (norton ff) doesnt work well over a CTTY COM1 link...
Theres no bells or whistles, but I want to throw in a filesize and attrib report one day when Im not in
such a rush...


#include <alloc.h>
#include <fcntl.h>
#include <string.h>
#include <io.h>
#include <dir.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include "filefind.h"

const fattrib=FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH;
const dattrib=FA_DIREC;

char currdir[200];

void process_dir(char *pspec,char *mname,char *mext,struct ffblk *ffblock) {
char drive[10], *dir, *name, ext[8], *path;
  dir=(char *)malloc(200);
  name=(char *)malloc(20);
  path=(char *)malloc(300);
  if ( (ffblock->ff_attrib&(FA_DIREC)) &&
       (ffblock->ff_name[0]!='.')      ) {
    fnsplit(pspec,drive,dir,name,ext);
    strcat(dir,ffblock->ff_name);
    strcat(dir,"\\");
    strcpy(currdir,dir);
    fnmerge(path,drive,dir,mname,mext);
    filefind(path);
    }
  free(dir);
  free(name);
  free(path);
  }

void filefind(char *spec) {
char drive[10], *dir,*name, ext[8], *pspec;
struct ffblk *ffblock;

  ffblock=(struct ffblk *)malloc(sizeof(struct ffblk));
  dir=(char *)malloc(200);
  name=(char *)malloc(20);
  pspec=(char *)malloc(300);

  fnsplit(spec,drive,dir,name,ext);
  fnmerge(currdir,drive,dir,"","");

  if (0==findfirst(spec,ffblock,fattrib)) {
    printf("file: %s%s \n",currdir,ffblock->ff_name);
    while (0==findnext(ffblock)) printf("file: %s%s \n",currdir,ffblock->ff_name);
    }

  fnmerge(pspec,drive,dir,"*",".*");

  if (0==findfirst(pspec,ffblock,dattrib)) {
    process_dir(pspec,name,ext,ffblock);
    while (0==findnext(ffblock)) process_dir(pspec,name,ext,ffblock);
    }

  free(dir);
  free(name);
  free(pspec);
  free(ffblock);

  }


int main(int argc, char *argv[]) {

  if (argc<2) {
    puts(" ");
    puts("File finder: ");
    puts("This utility searches the directory structure, starting");
    puts(" at the current or specified dir for a file spec (wild cards valid)");
    puts(" ");
    puts("Example:  filefind *.c");
    exit(1);
    }

  printf("Searching for %s...\n",argv[1]);

  filefind(argv[1]);

  return 0;
  }
Technical Details
Message-ID: <27442@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
References: <1992Aug27.044445.22165@uwm.edu> <BtMqnB.9J0@mentor.cc.purdue.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!snorkelwacker.mit.edu!ai-lab!hal.gnu.ai.mit.edu!rwed
From: rwed@hal.gnu.ai.mit.edu (N7YVM)
Newsgroups: comp.os.msdos.programmer
Subject: Re: WANTED: Code to search DOS directory/subdirectories
Message-ID: <27442@life.ai.mit.edu>
Date: 1 Sep 92 17:56:31 GMT
References: <1992Aug27.044445.22165@uwm.edu> <BtMqnB.9J0@mentor.cc.purdue.edu>
Sender: news@ai.mit.edu
Distribution: comp.os.msdos.programmer
Organization: /etc/organization
Lines: 90