home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
ff2b.zip
/
FF.C
next >
Wrap
C/C++ Source or Header
|
1991-06-27
|
7KB
|
210 lines
/*$TITLE 'File Find Tool FF'*/
/*──────────────────────────────────────────────────────────────────*/
/* FF.C (c) B. Kunrath 1989, 1990, 1991 */
/* Modified for dual mode by D. Plum 1991 */
/* Function: */
/* - searches for matching files on an entire disk. */
/* */
/* Tools used: */
/* - IBM OS/2 1.3 Extended Edition */
/* - IBM OS/2 Programming Tools and Information 1.3 */
/* - Microsoft C 6.0 */
/* */
/* Used API's: */
/* DosQCurDisk */
/* DosSelectDisk */
/* DosFindFirst */
/* DosFindNext */
/* DosFindCLose */
/* */
/*──────────────────────────────────────────────────────────────────*/
#define INCL_BASE
#define INCL_DOSDEVICES
#include <os2.h>
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include <direct.h>
#include <malloc.h>
#define WILDCARD_LEN 15
#define ATTR_READ_ONLY 0x01
#define ATTR_HIDDEN_FILES 0x02
#define ATTR_SYSTEM_FILES 0x04
#define ATTR_INCL_SUBDIRS 0x10
#define ATTR_INCL_ARCHIVE 0x20
UCHAR cwd[256],oldCwd[255];
USHORT searchHandle = 1;
USHORT searchCnt = 1;
FILEFINDBUF ffb;
UCHAR wildCard[WILDCARD_LEN+1];
USHORT driveNr;
ULONG driveMap;
BOOL printed = FALSE;
void ExecHead(void);
void ExecLine(void);
void FileFind(void);
int main (int argc, char *argv[])
{
DosQCurDisk(&driveNr, &driveMap);
if (oldCwd[strlen(getcwd(oldCwd, sizeof(oldCwd) - 1)) - 1] == '\\')
oldCwd[strlen(oldCwd) - 1] = 0;
if ((argc < 2) || (strlen(argv[1]) > WILDCARD_LEN))
{
printf("FileFind 1.01 Copyright ╕ B. Kunrath, Fa. OBIS GmbH 1989, 1990, 1991\n");
printf("Usage: ff [Drive]<Filename>\n");
printf(" Drive - The disk drive to be searched\n");
printf(" Filename - The filename to be searched for, including\n");
printf(" wildcards if desried, but excluding pathname.\n");
printf("Examples:\n");
printf(" ff a:\\*.c - find all files matching *.c on drive a:\n");
printf(" ff hennes.idx - find hennes.idx on the current drive\n");
printf("Exit(%d)...\n", ERROR_INVALID_PARAMETER);
exit(ERROR_INVALID_PARAMETER);
}
else
{
strcpy(wildCard, argv[1]);
printf("Searching for '%s'\n", wildCard );
};
if (argv[1][1] == ':' && isalpha(argv[1][0]))
{
DosSelectDisk (toupper(argv[1][0]) - 0x40);
if (wildCard[2]=='\\')
strcpy(wildCard, &wildCard[3]);
else
strcpy(wildCard, &wildCard[2]);
}
else
if (wildCard[0]=='\\')
strcpy(wildCard, &wildCard[1]);
chdir("\\");
FileFind();
if (!printed)
printf("No matching files found.\n");
DosSelectDisk (driveNr);
chdir(oldCwd);
return 0;
}
void ExecHead(void)
{
printf(" Size Date Time Pathname\n");
printed = TRUE;
return;
}
void ExecLine(void)
{
if (!printed)
ExecHead();
printf("%8ld %2d/%02d/%02d %2d:%02d %s\\%s\n",
ffb.cbFile,
ffb.fdateLastWrite.month,
ffb.fdateLastWrite.day,
(ffb.fdateLastWrite.year + 80) % 100,
ffb.ftimeLastWrite.hours,
ffb.ftimeLastWrite.minutes,
cwd, ffb.achName);
return;
}
void FileFind(void)
{
struct DIRNAMESAVE
{
struct DIRNAMESAVE *next;
UCHAR name[sizeof ffb.achName];
} *first = NULL, *last = NULL, *new = NULL;
if (cwd[strlen(getcwd(cwd, sizeof(cwd) - 1)) - 1] == '\\')
cwd[strlen(cwd) - 1] = 0;
searchHandle = 1;
searchCnt = 1;
DosFindFirst( wildCard, /* The file specification */
&searchHandle, /* handle -> return */
ATTR_READ_ONLY | /* Attributes of files */
ATTR_HIDDEN_FILES |
ATTR_SYSTEM_FILES ,
&ffb, /* Info. Buffer */
sizeof( FILEFINDBUF ), /* size of Info. Buffer */
&searchCnt, /* How many to search ? */
0L );
while (searchCnt)
{
ExecLine();
DosFindNext( searchHandle,
&ffb,
sizeof( FILEFINDBUF ),
&searchCnt);
}
DosFindClose( searchHandle );
searchHandle = 1;
searchCnt = 1;
DosFindFirst( "*.*", /* The file specification */
&searchHandle, /* handle -> return */
ATTR_READ_ONLY | /* Attributes of files */
ATTR_HIDDEN_FILES |
ATTR_SYSTEM_FILES |
ATTR_INCL_SUBDIRS,
&ffb, /* Info. Buffer */
sizeof( FILEFINDBUF ), /* size of Info. Buffer */
&searchCnt, /* How many to search ? */
0L ); /* reserved */
while (searchCnt)
{
if (ffb.attrFile & 0x10 && ffb.achName[0] != '.')
if((new = malloc(sizeof(struct DIRNAMESAVE))) != NULL)
{
new->next = NULL;
strcpy(new->name, ffb.achName);
if(first == NULL)
first = new;
else
last->next = new;
last = new;
}
else
{
printf("Insufficient memory.\n");
exit(1);
}
DosFindNext( searchHandle,
&ffb,
sizeof( FILEFINDBUF ),
&searchCnt);
}
DosFindClose( searchHandle );
while(first != NULL)
{
chdir(new->name);
FileFind();
chdir("..");
new = first;
first = first->next;
free(new);
}
};