home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
YAFF.ZIP
/
YAFF.C
next >
Wrap
C/C++ Source or Header
|
1992-09-11
|
5KB
|
174 lines
/* yaff.c yet another file finder also y + my initials (aff)
Andrew Frantz CIS = 70712.3547
This file was originally made for DOS usage, this release
incorportates HPFS long file names...Please subscribe to the
Hackker Ethic ("Hacker" 1984 S. Levy) which calls for the
1. post all source
2. enhance and learn from others source.
3. etc.
*/
#include <stdio.h>
#include <conio.h>
#include <os2.h>
#include <string.h>
/*static FILEFINDBUF3 findBuffer ;*/
int findInSubs(char *), display(char *);
static char input[13];
int total = 0;
long tbytes = 0;
void dt_time(unsigned hour, char *dy);
/*==================================================================*/
int main(int argc, char *argv[])
{
FILEFINDBUF3 findBuffer ;
HDIR findHandle = 0xFFFFFFFF ; /* Let OS/2 get us the handle */
int findCount = 1 ;
USHORT rc ;
char newPath[256], path[256], oldPath[256], path2[256];
if(argc < 2)
{
printf("Command Line Syntax dserch filespec !!\n");
// exit(0);
}
else
if(argc == 2)
strcpy(input,argv[1]);
strcpy(path,"\\");
printf("\n%20s\n\n","OS/2 File Search A. Frantz 1992");
strcpy(oldPath, path);
display((char *) &path); /*find files arg under root*/
strcat(path, "*.*");
/* DosFindFirst(PSZ pszFileSpec,
PHDIR phdir,
ULONG flAttribute,
PVOID pfindbuf,
ULONG cbBuf,
PULONG pcFileNames,
ULONG ulInfoLevel);
*/
if(rc = DosFindFirst(path ,&findHandle ,FILE_DIRECTORY ,
&findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
(ULONG)0x0001))
return rc;
while(!rc)
{
if (strcmp(findBuffer.achName,".") && strcmp(findBuffer.achName,".."))
{
if (findBuffer.attrFile == FILE_DIRECTORY )
{
strcpy(path2, oldPath);
strcat(path2 ,findBuffer.achName);
display((char *) &path2); /* prints all in this dir */
findInSubs((char *) &path2); /*check for argument in all subdirs*/
}
}
rc = DosFindNext(findHandle,
&findBuffer,
sizeof(findBuffer),
(PULONG) &findCount);
}
printf("\n\nTotal Files Found %d Total byte Count %ld\n",total, tbytes);
}
/* ================================================================*/
int findInSubs(char *dir)
{
FILEFINDBUF3 findBuffer ;
HDIR findHandle = 0xFFFFFFFF ; /* Let OS/2 get us the handle */
int findCount = 1 ;
USHORT rc ;
char newPath[256], path[256], new_dir[256];
strcpy(new_dir, dir);
strcat(new_dir, "\\");
strcat(new_dir, "*.*");
if(rc = DosFindFirst(new_dir ,&findHandle ,FILE_DIRECTORY ,
&findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
(ULONG)0x0001))
return rc;
while(!rc)
{
if (strcmp(findBuffer.achName,".") && strcmp(findBuffer.achName,".."))
{
if (findBuffer.attrFile == FILE_DIRECTORY )
{
strcpy(path, dir);
strcat(path,"\\");
strcat(path ,findBuffer.achName);
display((char *) &path);
findInSubs((char *) &path); /*recursize step*/
}
}
rc = DosFindNext(findHandle,
&findBuffer,
sizeof(findBuffer),
(PULONG) &findCount);
}
}
/*===================================================================*/
int display(char *path2)
{
HDIR findHandle = 0xFFFFFFFF ; /* Let OS/2 get us the handle */
int findCount = 1 ;
USHORT rc ;
FILEFINDBUF3 findBuffer ;
/* USHORT day , mon, year, hour , min;*/
char *blank[] = {" "}, dy[3];
char path[256];
strcpy(dy, " ");
strcpy(path, path2);
strcat(path, "\\");
strcat(path, input);
if(rc = DosFindFirst(path ,&findHandle ,0 ,
&findBuffer , (ULONG)sizeof(findBuffer) , (PULONG)&findCount ,
(ULONG)0x0001))
{
return rc;
}
printf("%s\n", path2);
while(!rc) {
if (findBuffer.attrFile != FILE_DIRECTORY )
{
dt_time(findBuffer.ftimeLastWrite.hours, dy);
printf("%s%-14s%12ld bytes ",blank[0], findBuffer.achName, findBuffer.cbFileAlloc);
printf("%02u/%02d/%02d %02d:%02d%s\n",
findBuffer.fdateLastWrite.month,
findBuffer.fdateLastWrite.day ,
findBuffer.fdateLastWrite.year+80,
findBuffer.ftimeLastWrite.hours,
findBuffer.ftimeLastWrite.minutes, dy);
total++;
tbytes += findBuffer.cbFileAlloc;
}
rc = DosFindNext(findHandle,
&findBuffer,
sizeof(findBuffer),
(PULONG) &findCount);
}
}
/*===================================================================*/
void dt_time(unsigned hour, char *dy)
{
if(hour == 0)
hour += 12;
if(hour >= 12)
strcpy(dy,"pm");
else
strcpy(dy, "am");
}
/*===================================================================*/