home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / FILEFIND.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  3KB  |  84 lines

  1. EXTPROC CEnvi2
  2. /*******************************************************************
  3.  *** FileFind - Use CEnvi2 to search this disk, or all disks, for ***
  4.  *** ver.1      files matching any given file spec.  Print names ***
  5.  ***            off all files found, and return find count.      ***
  6.  *******************************************************************/
  7.  
  8. main(argc,argv)
  9. {
  10.    if ( 2 != argc  ||  !strcmp("/?",argv[1])  ||  !stricmp("/help",argv[1])  ||  0 == argv[1][0] ) {
  11.       FindCount = 0;
  12.       Instructions();
  13.    } else {
  14.       FindCount = FindFiles(argv[1]);
  15.    }
  16.    return(FindCount);
  17. }
  18.  
  19. FindFiles(spec) // find files matching spec, and return number found
  20. {
  21.    // determine spec searching for to see if search all drives, all of one
  22.    // drive, or specified subbdirectories
  23.    NameParts = SplitFileName(spec);
  24.    if ( NameParts.dir[0] == 0 ) {
  25.       count = SearchAllDrives(spec);
  26.    } else if ( 2 == strlen(NameParts.dir)  &&  NameParts.dir[1] == ':' )
  27.       count = SearchOneDrive(NameParts.dir[0],spec+2);
  28.    else {
  29.       count = SearchSubdir(spec);
  30.    }
  31.    return(count);
  32. }
  33.  
  34. SearchSubdir(SearchSpec) // search from SearchSpec for all matching files
  35. {
  36.    List = Directory(SearchSpec,TRUE,FATTR_RDONLY|FATTR_HIDDEN|FATTR_SYSTEM|FATTR_SUBDIR|FATTR_ARCHIVE);
  37.    if ( NULL == List )
  38.       return(0);
  39.    DisplayFoundList(List);
  40.    return(1 + GetArraySpan(List));
  41. }
  42.  
  43. SearchOneDrive(DriveLetter,SearchSpec)
  44. {
  45.    sprintf(FullSearchSpec,"%c:\\%s",DriveLetter,SearchSpec);
  46.    return SearchSubDir(FullSearchSpec);
  47. }
  48.  
  49. SearchAllDrives(SearchSpec) // look on all valid drives
  50. {
  51.    TotalFound = 0;
  52.    for ( DriveLetter = 'C'; DriveLetter <= 'Z'; DriveLetter++ ) {
  53.       sprintf(DriveCurdir,"%c:.",DriveLetter);
  54.       if ( NULL != FullPath(DriveCurdir) ) {
  55.          TotalFound += SearchOneDrive(DriveLetter,SearchSpec);
  56.       }
  57.    }
  58.    return(TotalFound);
  59. }
  60.  
  61. DisplayFoundList(list)
  62. {
  63.    count = 1 + GetArraySpan(list);
  64.    for ( i = 0; i < count; i++ ) {
  65.       printf("%-45s  %-8d  %s",list[i].name,list[i].size,ctime(list[i].Write)+4);
  66.    }
  67. }
  68.  
  69. Instructions()
  70. {
  71.    printf("\a\n")
  72.    printf("FileFind.cmd - Find File in directory tree or on any drive.\n")
  73.    printf("\n")
  74.    printf("SYNTAX: FileFind FileSpec\n")
  75.    printf("\n")
  76.    printf("Where:  FileSpec Specification to match in finding file\n")
  77.    printf("\n")
  78.    printf("Examples: FileFind q*.bak        Find all *.bak files on all hard drives\n")
  79.    printf("          FileFind E:q*.bak      Find all *.bak files on drive E:\n")
  80.    printf("          FileFind foo\\q*.bak    Find all *.bak in subdirectory foo and below\n")
  81.    printf("          FileFind E:\\foo\\q*.bak Find all *.bak in subdirectory E:\\foo and below\n")
  82. }
  83.  
  84.