#include "nw.h"
#include <conio.h>

main ( int argc, char *argv[] ) {

	int result, count=0;
	struct scanFileReq request;
	struct scanFileRep reply;

	clrscr();
	if ( argc != 2 ) {

	       printf( "Usage: FILEINFO path\n");
	       exit(1);
	}
	/* Initialize Request & Reply structures */
	request.Length = sizeof( request ) - 2;
	request.Function = 0X0F;             /* Function F - Get file info */
	request.SequenceNumber  =  0XFFFF;   /* Use -1 as first sequence   */
	request.DirectoryHandle =  0;	     /* No handle, use full path from user */
	request.SearchAttributes =  6;       /* Search Normal, Hidden, & System */
	request.FilePathLength = strlen( argv[1] );
	movmem( argv[1], request.FilePath, request.FilePathLength );

	reply.Length = sizeof( reply ) - 2;

	/* Now cycle through calls to GetFileInfo until no more files are found */
	while (1) {
	   result = GetFileInfo( &request, &reply );
	   if (result == 0x89) {
	      printf( "No Search Privileges for this path\n");
	      exit(1);
	   }
	   if (result == 0x98) {
	      printf( "Volume does not exist"
		      "use Volume:Directory\\Directory\\File\n");
	      exit(1);
	   }
	   if   (result == 0x9C) {
	      printf( "Invalid path "
		      "use Volume:Directory\\Directory\\File\n");
	      exit(1);
	   }
	   if ( result == 0XFF ) {
	      exit(1);
	   }
	   PrintFileInfo(&reply);
	   printf("\n");

	   if( ++count>=4 ) {
	      printf("Press any key to continue");
	      count=0;
	      getch();
	      putchar('\n');
	   }

	   request.SequenceNumber = reply.SequenceNumber;
	}
}

