----------------------------- GDIR.DOC (cut here) ----------------------------- Gdir is an enhancement over DOS's dir command. It includes file attributes in its display, allows you to perform directories of hidden and system files, and also allows you to recursively check all of a directory's subdirectories as well. Usage: GDIR [/I] [/A] [/D] [/R] [d:][dirspec][filespec] Options: /I - Include invisible (hidden and system) files in listing. Default is to not list invisible files. /A - Include files with leading dot in listing. Default is to not list files with a leading dot. /D - Only list directories. Default is to list directories and files. /R - Recursively GDIR on all subdirectories Parameters: d - drive to search; defaults to current drive dirspec - directory to search; defaults to current directory filespec - file(s) to search for; defaults to "*.*" Note: filespec may be wildcarded. If file extension is left blank, it will default to none, not "*" Returns: 0 = normal return 1 = no files found 2 = syntax error Notes: - Any switches must be given before the path. - Unlike dir, "gdir \foo" where \foo is a directory will only show the directory entry for \foo (which will show the /D, or directory, attribute). It will not list the files contained in \foo. Use "gdir \foo\" for to list the files in \foo. Examples: GDIR Normal directory listing of current directory. GDIR /I \*.COM Lists all .COM files in the root directory, including hidden and system files. GDIR /D /R \ Lists all directories on current drive. GDIR /D /R /A \ Same as above, but includes "." and ".." directory entries as well. Attribute flags: Gdir displays the following attribute flags for a file: /R - read-only /S - system /M - modified /H - hidden /D - directory ------------------------- end of GDIR.DOC (cut here) -------------------------- ------------------------------ GDIR.C (cut here) ------------------------------ /* --------------------------------- |GLOBAL DIRECTORY SEARCH PROGRAM| | by R. Lenoil - 8/16/84 | --------------------------------- Placed in the public domain, June 1986. Author's electronic mail address: USENET: lenoil@mit-eddie.uucp ARPA: lenoil@eddie.mit.edu */ /****************************************************************************** Effect: Shows directory information for files in several directories. Usage: GDIR [/I] [/A] [/D] [/R] [d:][dirspec][filespec] Parameters: d - drive to search; defaults to current drive dirspec - directory to search; defaults to current directory filespec - file(s) to search for; defaults to "*.*" Note: filespec may be wildcarded. If file extension is left blank, it will default to none, not "*" Options: /I - Include invisible (hidden and system) files in listing. Default is to not list invisible files. /A - Include files with leading dot in listing. Default is to not list files with a leading dot. /D - Only list directories. Default is to list directories and files. /R - Recursively GDIR on all subdirectories Returns: 0 = normal return 1 = no files found 2 = syntax error ******************************************************************************/ /* Updated 7/12/85 to not use TREE.COM for directory search */ #include #include #include /* attribute bits */ #define READ_ONLY 1 #define HIDDEN 2 #define SYSTEM 4 #define SUBDIRS 16 #define MODIFIED 32 /* strings */ #define PATH_SEPERATOR "\\" #define FNAME_DEFAULT "*.*" /* system calls */ #define SET_DTA 0x1a #define GET_DTA 0x2f #define FIND_FIRST 0x4e #define FIND_NEXT 0x4f /*++++++++++++++++++++ External Definitions ++++++++++++++++++++*/ static char fname_default[] = FNAME_DEFAULT, path_seperator[] = PATH_SEPERATOR, switchar; /* holds system switch character */ char *strrchr(); /* finds last occurrence of a character in a string */ struct dta /* disk transfer area (for find) */ { char rsvd[21], /* reserved for DOS */ attrib; /* file atribute */ struct /* Rep for file modification date */ { unsigned twosec : 5; unsigned min : 6; unsigned hour : 5; unsigned day : 5; unsigned month : 4; unsigned year : 7; } time; long size; /* file size */ char name[13]; /* file name */ }; /*++++++++++++++++++++ end External Definitions ++++++++++++++++++++*/ /*++++++++++++++++++++ procedure MAIN ++++++++++++++++++++*/ main(nargs,args) int nargs; /* # of words on cmd line */ char *args[]; /* array of ptrs to words */ { char search_string[100], /* search string passed to DOS */ fname[13], /* filename to search for */ get_switchar(); /* returns switchar */ register i; int attribs = 0, /* attributes to search for */ subdirs = 0, /* global search or not */ all = 0, /* print all files or not */ files; /* number of files matched */ /* get switch character */ switchar = get_switchar(); /* uppercase args */ for (i=0; ++i < nargs;) strupr(args[i]); /* parse switches */ while (++args,--nargs,**args == switchar && nargs) { if (args[0][2]) Syntax(); switch (toupper(args[0][1])) { case 'I': attribs |= HIDDEN + SYSTEM; break; case 'A': all = 1; break; case 'R': subdirs = 1; break; case 'D': attribs |= SUBDIRS; break; default: Syntax(); } } if (nargs > 1) Syntax(); if (rootpath( (nargs)? *args : fname_default , search_string)) files = 0; else { char *name_start = strrchr(search_string,'\\')+1; if (*name_start) { strncpy(fname,name_start,12); fname[12] = *name_start = 0; } else strcpy(fname,fname_default); files = gdir(search_string,fname,attribs,subdirs,all); } printf("\n Found %d file%c\n",files,files==1? ' ' : 's'); return (files)? 0 : 1; } /*++++++++++++++++++++ end procedure MAIN ++++++++++++++++++++*/ /*++++++++++++++++++++ procedure SYNTAX ++++++++++++++++++++*/ Syntax() { printf("Usage: GDIR [/I] [/A] [/R] [/D] [d:][path\\][filespec]"); exit(2); } /*++++++++++++++++++++ end procedure SYNTAX ++++++++++++++++++++*/ /*++++++++++++++++++++ procedure GDIR ++++++++++++++++++++*/ gdir(path,fname,attribs,subdirs,all) char *path,*fname; /* search path */ /* Note: path must be as large as PATHMAX */ /* Warning: path is modified */ int attribs, /* attribs to search for */ subdirs, /* TRUE = do recursive search */ all; /* TRUE = show files starting with "." */ { struct dta findbuf; char *name_start; /* start of filename in path */ unsigned pdta; /* address of dta on entry */ union REGS regs; int files_found = 0; /* Save dta address, and set to ours */ regs.h.ah = GET_DTA; intdos(®s,®s); pdta = regs.x.bx; regs.h.ah = SET_DTA; regs.x.dx = (unsigned) &findbuf; intdos(®s,®s); if ((name_start = strrchr(path,'\\') + 1) == (char *)1) name_start = path; regs.h.ah = FIND_FIRST; regs.x.cx = attribs | SUBDIRS; regs.x.dx = (unsigned) path; /* find all matches in specified directory */ strcpy(name_start,fname); for (;intdos(®s,®s),!regs.x.cflag;regs.h.ah=FIND_NEXT) if (attribs & SUBDIRS && !(findbuf.attrib & SUBDIRS)) continue; else if (*findbuf.name != '.' || all) { strcpy(name_start,findbuf.name); display(path,&findbuf); ++files_found; } if (subdirs) /* recurse on subdirs */ { regs.h.ah = FIND_FIRST; regs.x.cx |= SUBDIRS; strcpy(name_start,fname_default); for (;intdos(®s,®s),!regs.x.cflag;regs.h.ah=FIND_NEXT) { if (findbuf.attrib & SUBDIRS && *findbuf.name != '.') { strcpy(name_start,findbuf.name); strcat(name_start,path_seperator); files_found += gdir(path,fname,attribs,subdirs,all); } } } /* Restore dta */ regs.h.ah = SET_DTA; regs.x.dx = pdta; intdos(®s,®s); return files_found; } /*++++++++++++++++++++ end procedure GDIR ++++++++++++++++++++*/ /*++++++++++++++++++++ procedure DISPLAY ++++++++++++++++++++*/ display(path,f) char *path; struct dta *f; #define T f->time { printf("%s %lu %.2u-%.2u-%.2u %.2u:%.2u:%.2u", path,f->size,T.month,T.day,80+T.year,T.hour,T.min,T.twosec*2); if (f->attrib & READ_ONLY) printf(" /R"); if (f->attrib & HIDDEN) printf(" /H"); if (f->attrib & SYSTEM) printf(" /S"); if (f->attrib & SUBDIRS) printf(" /D"); if (f->attrib & MODIFIED) printf(" /M"); printf("\n"); } #undef T /*++++++++++++++++++++ end procedure DISPLAY ++++++++++++++++++++*/ /*++++++++++++++++++++ procedure GET_SWITCHAR ++++++++++++++++++++*/ char get_switchar() { union REGS regs; regs.x.ax = 0x3700; intdos(®s,®s); return regs.h.dl; } /*++++++++++++++++++++ end procedure GET_SWITCHAR ++++++++++++++++++++*/ -------------------------- end of GDIR.C (cut here) ---------------------------